//:k8 abv 6 Jan 98: using parameter "step.group" for writing assemblies/shapes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Pour le transfert (write) // Pour NewModel et Write : definition de produit (temporaire ...) #include #include #include #include #include #include #include #include // steptrans #include #include #include #include #include #include #include #include #include #include #include #include extern "C" { static void cleanpilot () { XSDRAW::Session()->ClearData(1); } } //======================================================================= //function : Init //purpose : //======================================================================= void XSDRAWSTEP::Init () { Handle(StepSelect_Activator) stepact = new StepSelect_Activator; if (STEPControl_Controller::Init()) // XSDRAW::SetNorm("STEP AP-214"); trop tot XSDRAW::SetController(XSControl_Controller::Recorded("STEP")); atexit (cleanpilot); } // ######## COMMANDE stepread : teste le Reader ######### //======================================================================= //function : stepread //purpose : //======================================================================= static Standard_Integer stepread (Draw_Interpretor& di/*theCommands*/, Standard_Integer argc, const char** argv) { // On admet le controller AP214 ou une variante DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); // Progress indicator Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); progress->SetScale ( 0, 100, 1 ); progress->Show(); STEPControl_Reader sr (XSDRAW::Session(),Standard_False); TCollection_AsciiString fnom,rnom; Standard_Boolean modfic = XSDRAW::FileAndVar (argv[1],argv[2],"STEP",fnom,rnom); if (modfic) di<<" File STEP to read : "<NewScope ( 20, "Loading" ); // On average loading takes 20% progress->Show(); if (modfic) readstat = sr.ReadFile (fnom.ToCString()); else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone; progress->EndScope(); progress->Show(); if (readstat != IFSelect_RetDone) { if (modfic) di<<"Could not read file "< 3); // nom = "." -> fichier deja lu Standard_Integer i, num, nbs, modepri = 1; if (fromtcl) modepri = 4; Handle(Message_Messenger) aDIMessenger = new Message_Messenger (new Draw_Printer(di)); while (modepri) { num = sr.NbRootsForTransfer(); if (!fromtcl) { di<<"NbRootsForTransfer="<Print(sr.RootForTransfer(i),aDIMessenger); di<<" Type:"<DynamicType()->Name()<<"\n"; } cout<<"Mode (0 End, 1 root n0 1, 2 one root/n0, 3 one entity/n0, 4 Selection) : "<>modepri; } if (modepri == 0) { di<<"End Reading STEP"<<"\n"; return 0; } if (modepri <= 2) { num = 1; if (modepri == 2) { cout<<"Root N0 : "<>num; } progress->NewScope ( 80, "Translation" ); progress->Show(); sr.WS()->MapReader()->SetProgress ( progress ); if (!sr.TransferRoot (num)) di<<"Transfer root n0 "< DRAW Shape: "<MapReader()->SetProgress ( 0 ); progress->EndScope(); progress->Show(); } else if (modepri == 3) { cout<<"Entity : "< DRAW Shape: "<Append(sr.RootForTransfer(j)); } else { di<<"List given by "< 4) di<<" "< 4 ? argv[4] : 0 ) ); } if (list.IsNull()) { di<<"No list defined. Give a selection name or * for all transferrable roots"<<"\n"; continue; } } else { cout<<"Name of Selection :"<Length(); di<<"Nb entities selected : "<NewScope ( 80, "Translation" ); progress->Show(); sr.WS()->MapReader()->SetProgress ( progress ); Message_ProgressSentry PSentry ( progress, "Root", 0, nbl, 1 ); for (ill = 1; ill <= nbl && PSentry.More(); ill ++, PSentry.Next()) { num = sr.Model()->Number(list->Value(ill)); if (num == 0) continue; if (!sr.TransferOne(num)) di<<"Transfer entity n0 "< DRAW Shape: "<MapReader()->SetProgress ( 0 ); progress->EndScope(); progress->Show(); } else di<<"Unknown mode n0 "<>modepri; if (modepri == 0) { di<<"End Reading STEP"<<"\n"; return 0; } if (!sr.TransferRoot (num)) di<<"Transfer root n0 "<>modepri; return 0; } // ######## COMMANDE steptrans : teste les transformations ######### //======================================================================= //function : steptrans //purpose : //======================================================================= static Standard_Integer steptrans (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc < 5) { di<<"give shape-name new-shape + entity-n0 entity-n0: AXIS2"<<"\n"; return 1; } TopoDS_Shape shape = DBRep::Get(argv[1]); if (shape.IsNull()) { di<<"Not a shape : "< 4) n2 = XSDRAW::GetEntityNumber(argv[4]); if (n1 > 0) ax1 = Handle(StepGeom_Axis2Placement3d)::DownCast (XSDRAW::Entity(n1)); if (n2 > 0) ax2 = Handle(StepGeom_Axis2Placement3d)::DownCast (XSDRAW::Entity(n2)); StepToTopoDS_MakeTransformed mktrans; if (mktrans.Compute (ax1,ax2)) { TopLoc_Location loc (mktrans.Transformation()); shape.Move (loc); // mktrans.Transform (shape); DBRep::Set (argv[2],shape); di<<"Transformed Shape as "<ActorWrite() ); if ( ! ActWrite.IsNull() ) ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly")); TopoDS_Shape shape = DBRep::Get(argv[2]); STEPControl_Writer sw (XSDRAW::Session(),Standard_False); Handle(Interface_InterfaceModel) stepmodel = sw.Model(); Standard_Integer nbavant = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities()); Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); progress->NewScope(90,"Translating"); progress->Show(); sw.WS()->TransferWriter()->FinderProcess()->SetProgress(progress); Standard_Integer stat = sw.Transfer (shape,mode); di<<"execution status : "<TransferWriter()->FinderProcess()->SetProgress(0); progress->EndScope(); progress->Show(); progress->NewScope(10,"Writing"); progress->Show(); // Que s est-il passe stepmodel = sw.Model(); Standard_Integer nbapres = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities()); if (nbavant > 0) di<<"Beware : Model not empty before transferring"<<"\n"; if (nbapres <= nbavant) di<<"Beware : No data produced by this transfer"<<"\n"; if (nbapres == 0) { di<<"No data to write"<<"\n"; return 0; } char nomfic[150] ; Standard_Integer modepri = 1; if (argc <= 3) { cout<<" Mode (0 end, 1 file) :"<> modepri; di << "Output mode " << modepri << "\n"; } else modepri = 2; if (modepri == 0) return 0; else if (modepri == 1) { cout << " Output file name :" << flush; cin >> nomfic; } else if (modepri == 2) strcpy (nomfic,argv[3]); di << " Output on file : " << nomfic << "\n"; stat = sw.Write(nomfic); switch (stat) { case IFSelect_RetVoid : di<<"No file written"<<"\n"; break; case IFSelect_RetDone : di<<"File "<EndScope(); progress->Show(); return 0; } //======================================================================= //function : testwritestep //purpose : //======================================================================= static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc != 3) { di << "ERROR in " << argv[0] << "Wrong Number of Arguments."<<"\n"; di << " Usage : " << argv[0] <<" file_name shape_name "<< "\n"; return 1; } STEPControl_Writer Writer; Standard_CString filename = argv[1]; TopoDS_Shape shape = DBRep::Get(argv[2]); IFSelect_ReturnStatus stat = Writer.Transfer(shape,STEPControl_AsIs); stat = Writer.Write(filename); if(stat != IFSelect_RetDone){ di<<"Error on writing file"<<"\n"; return 1; } di<<"File Is Written"<<"\n"; return 0; } //======================================================================= //function : countexpected //purpose : //======================================================================= static Standard_Integer countexpected (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) { Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); Handle(IFSelect_WorkSession) WS = pilot->Session(); const Interface_Graph& graph = WS->Graph(); Handle(TColStd_HSequenceOfTransient) roots = WS->GiveList("xst-transferrable-roots", ""); STEPSelections_Counter cnt; for (Standard_Integer i =1 ; i <= roots->Length(); i++) { cnt.Count(graph,roots->Value(i)); } di<< "Instances of Faces \t: "<Session(); const Interface_Graph& graph = WS->Graph(); STEPSelections_AssemblyExplorer exp(graph); exp.Dump(cout); return 0; } // ######## COMMANDE stepwrite : teste le Writer ######### void XSDRAWSTEP::InitCommands (Draw_Interpretor& theCommands) { const char* g = "DE: STEP"; // Step transfer file commands XSDRAWSTEP::Init(); XSDRAW::LoadDraw(theCommands); theCommands.Add("stepwrite" , "stepwrite mode[0-4 afsmw] shape", __FILE__, stepwrite, g); theCommands.Add("testwritestep", "testwritestep filename.stp shape", __FILE__, testwrite, g); theCommands.Add("stepread", "stepread [file]", __FILE__, stepread, g); theCommands.Add("testreadstep", "testreadstep [file] [name DRAW]", __FILE__, testread, g); theCommands.Add("steptrans", "steptrans shape stepax1 stepax2", __FILE__, steptrans, g); theCommands.Add("countexpected","TEST", __FILE__, countexpected, g); theCommands.Add("dumpassembly", "TEST", __FILE__, dumpassembly, g); theCommands.Add("readstep", "readstep [file]", __FILE__, readstep, g); }