From d671b083f8ebafb83fd7e8d3950724fc0360f1a1 Mon Sep 17 00:00:00 2001 From: gka Date: Wed, 2 Aug 2017 11:36:05 +0300 Subject: [PATCH] Modificarion STEP translator for ISCAR project Modification for loading a few STEP files in the model --- src/IFSelect/IFSelect_WorkSession.cxx | 7 +- ...epVisual_RWPresentationLayerAssignment.cxx | 20 +++-- src/StepData/StepData_StepModel.cxx | 13 ++- src/StepData/StepData_StepReaderData.cxx | 4 +- src/StepSelect/StepSelect_WorkLibrary.cxx | 12 ++- ...StepVisual_PresentationLayerAssignment.cxx | 2 +- src/XDEDRAW/XDEDRAW_Common.cxx | 85 +++++++++++++++++++ src/XSDRAWSTEP/XSDRAWSTEP.cxx | 69 +++++++++++++-- 8 files changed, 186 insertions(+), 26 deletions(-) diff --git a/src/IFSelect/IFSelect_WorkSession.cxx b/src/IFSelect/IFSelect_WorkSession.cxx index 611bb30911..b9416b4954 100644 --- a/src/IFSelect/IFSelect_WorkSession.cxx +++ b/src/IFSelect/IFSelect_WorkSession.cxx @@ -212,7 +212,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile { if (thelibrary.IsNull()) return IFSelect_RetVoid; if (theprotocol.IsNull()) return IFSelect_RetVoid; - Handle(Interface_InterfaceModel) model; + Handle(Interface_InterfaceModel) model =myModel; IFSelect_ReturnStatus status = IFSelect_RetVoid; try { OCC_CATCH_SIGNALS @@ -1701,11 +1701,12 @@ Standard_Integer IFSelect_WorkSession::RunTransformer { Standard_Integer effect = 0; if (transf.IsNull() || !IsLoaded()) return effect; + Handle(Interface_InterfaceModel) newmod; // Null au depart Interface_CheckIterator checks; checks.SetName("X-STEP WorkSession : RunTransformer"); Standard_Boolean res = transf->Perform - (thegraph->Graph(),theprotocol,checks,newmod); + (thegraph->Graph(),theprotocol,checks,myModel); if (!checks.IsEmpty(Standard_False)) { Handle(Message_Messenger) sout = Message::DefaultMessenger(); @@ -3055,7 +3056,7 @@ Handle(IFSelect_Selection) IFSelect_WorkSession::GiveSelection } Handle(IFSelect_Selection) sel; - if (np >= 0) + if (np >= 0) { nomsel[np] = 0; } diff --git a/src/RWStepVisual/RWStepVisual_RWPresentationLayerAssignment.cxx b/src/RWStepVisual/RWStepVisual_RWPresentationLayerAssignment.cxx index 2cf4d65934..1a3b1db4d1 100644 --- a/src/RWStepVisual/RWStepVisual_RWPresentationLayerAssignment.cxx +++ b/src/RWStepVisual/RWStepVisual_RWPresentationLayerAssignment.cxx @@ -52,14 +52,18 @@ void RWStepVisual_RWPresentationLayerAssignment::ReadStep Handle(StepVisual_HArray1OfLayeredItem) aAssignedItems; StepVisual_LayeredItem aAssignedItemsItem; Standard_Integer nsub3; - if (data->ReadSubList (num,3,"assigned_items",ach,nsub3)) { - Standard_Integer nb3 = data->NbParams(nsub3); - aAssignedItems = new StepVisual_HArray1OfLayeredItem (1, nb3); - for (Standard_Integer i3 = 1; i3 <= nb3; i3 ++) { - //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed - if (data->ReadEntity (nsub3,i3,"assigned_items",ach,aAssignedItemsItem)) - aAssignedItems->SetValue(i3,aAssignedItemsItem); - } + if (data->ReadSubList(num, 3, "assigned_items", ach, nsub3)) { + Standard_Integer nb3 = data->NbParams(nsub3); + if (nb3) + { + + aAssignedItems = new StepVisual_HArray1OfLayeredItem(1, nb3); + for (Standard_Integer i3 = 1; i3 <= nb3; i3++) { + //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed + if (data->ReadEntity(nsub3, i3, "assigned_items", ach, aAssignedItemsItem)) + aAssignedItems->SetValue(i3, aAssignedItemsItem); + } + } } //--- Initialisation of the read entity --- diff --git a/src/StepData/StepData_StepModel.cxx b/src/StepData/StepData_StepModel.cxx index 306609cea8..2f7b682fef 100644 --- a/src/StepData/StepData_StepModel.cxx +++ b/src/StepData/StepData_StepModel.cxx @@ -141,11 +141,22 @@ void StepData_StepModel::SetIdentLabel Standard_Integer num = Number(ent); if (!num) return; + Standard_Integer nbEnt = NbEntities(); if(theidnums.IsNull()) { - theidnums = new TColStd_HArray1OfInteger(1, NbEntities()); + theidnums = new TColStd_HArray1OfInteger(1,nbEnt); theidnums->Init(0); } + else if(nbEnt > theidnums->Length()) + { + Standard_Integer prevLength = theidnums->Length(); + Handle(TColStd_HArray1OfInteger) idnums1 = new TColStd_HArray1OfInteger(1,nbEnt); + idnums1->Init(0); + Standard_Integer k =1; + for( ; k <= prevLength; k++) + idnums1->SetValue(k , theidnums->Value(k)); + theidnums = idnums1; + } theidnums->SetValue(num,ident); } diff --git a/src/StepData/StepData_StepReaderData.cxx b/src/StepData/StepData_StepReaderData.cxx index bcfd329a9a..ad4d755dbe 100644 --- a/src/StepData/StepData_StepReaderData.cxx +++ b/src/StepData/StepData_StepReaderData.cxx @@ -1017,8 +1017,8 @@ Standard_Boolean StepData_StepReaderData::ReadReal(const Standard_Integer num, Handle(String) errmess; // Null si pas d erreur if (nump > 0 && nump <= NbParams(num)) { const Interface_FileParameter& FP = Param(num,nump); - if (FP.ParamType() == Interface_ParamReal) val = - Interface_FileReaderData::Fastof(FP.CValue()); + if (FP.ParamType() == Interface_ParamReal || FP.ParamType() == Interface_ParamInteger) + val = Interface_FileReaderData::Fastof(FP.CValue()); else errmess = new String("Parameter n0.%d (%s) not a Real"); } else errmess = new String("Parameter n0.%d (%s) absent"); diff --git a/src/StepSelect/StepSelect_WorkLibrary.cxx b/src/StepSelect/StepSelect_WorkLibrary.cxx index 272f079a0b..c55eb55615 100644 --- a/src/StepSelect/StepSelect_WorkLibrary.cxx +++ b/src/StepSelect/StepSelect_WorkLibrary.cxx @@ -70,8 +70,16 @@ Standard_Integer StepSelect_WorkLibrary::ReadFile long status = 1; DeclareAndCast(StepData_Protocol,stepro,protocol); if (stepro.IsNull()) return 1; - Handle(StepData_StepModel) stepmodel = new StepData_StepModel; - model = stepmodel; + //ISCAR + Handle(StepData_StepModel) stepmodel; + if(!model.IsNull()) + stepmodel = Handle(StepData_StepModel)::DownCast(model); + if(stepmodel.IsNull()) + { + stepmodel = new StepData_StepModel; + model = stepmodel; + } + StepFile_ReadTrace (0); char *pName=(char *)name; status = StepFile_Read (pName,stepmodel,stepro); diff --git a/src/StepVisual/StepVisual_PresentationLayerAssignment.cxx b/src/StepVisual/StepVisual_PresentationLayerAssignment.cxx index c48d676191..eed606e60f 100644 --- a/src/StepVisual/StepVisual_PresentationLayerAssignment.cxx +++ b/src/StepVisual/StepVisual_PresentationLayerAssignment.cxx @@ -70,5 +70,5 @@ StepVisual_LayeredItem StepVisual_PresentationLayerAssignment::AssignedItemsValu Standard_Integer StepVisual_PresentationLayerAssignment::NbAssignedItems () const { - return assignedItems->Length(); + return (assignedItems.IsNull() ? 0 : assignedItems->Length()); } diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 2902446b43..755921d20a 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -47,6 +47,8 @@ #include #include #include +#include +#include #include //============================================================ @@ -512,6 +514,87 @@ static Standard_Integer Expand (Draw_Interpretor& di, Standard_Integer argc, con } return 0; } +static Standard_Integer testSTEP(Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc <3) { + di << "Use: " << argv[0] << " Doc filename [mode]: read STEP file to a document\n"; + return 0; + } + + DeclareAndCast(STEPControl_Controller, ctl, XSDRAW::Controller()); + if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); + + STEPCAFControl_Reader reader(XSDRAW::Session(), Standard_True); + + if (argc == 4) { + Standard_Boolean mode = Standard_True; + for (Standard_Integer i = 0; argv[3][i]; i++) + switch (argv[3][i]) { + case '-': mode = Standard_False; break; + case '+': mode = Standard_True; break; + case 'c': reader.SetColorMode(mode); break; + case 'n': reader.SetNameMode(mode); break; + case 'l': reader.SetLayerMode(mode); break; + case 'v': reader.SetPropsMode(mode); break; + } + } + + TCollection_AsciiString fnom, rnom; + Standard_Boolean modfic = XSDRAW::FileAndVar(argv[2], argv[1], "STEP", fnom, rnom); + if (modfic) di << " File STEP to read : " << fnom.ToCString() << "\n"; + else di << " Model taken from the session : " << fnom.ToCString() << "\n"; + // di<<" -- Names of variables BREP-DRAW prefixed by : "<NbStartingEntities() > 0) readstat = IFSelect_RetDone; + if (readstat != IFSelect_RetDone) { + if (modfic) di << "Could not read file " << fnom.ToCString() << " , abandon\n"; + else di << "No model loaded\n"; + return 1; + } + //////////////////////////////////////////////////////// + //Modification for Drawing2.stp + Handle(StepData_StepModel) aModel = Handle(StepData_StepModel)::DownCast(reader.ChangeReader().Model()); + Standard_Integer i = 1 , nbEnt = aModel->NbEntities(); + for (; i <= nbEnt; i++) + { + Handle(Standard_Transient) ent = aModel->Value(i); + if (ent->IsKind(STANDARD_TYPE(StepBasic_ProductDefinition))) + break; + } + //product defintion is not found + if (i > nbEnt) + Interface_Static::SetIVal("read.step.all.shapes", 1); + else + Interface_Static::SetIVal("read.step.all.shapes", 0); + reader.NbRootsForTransfer(); + + ///////////////////////////////////////////////////////// + Handle(TDocStd_Document) doc; + if (!DDocStd::GetDocument(argv[1], doc, Standard_False)) { + Handle(TDocStd_Application) A = DDocStd::GetApplication(); + A->NewDocument("BinXCAF", doc); + TDataStd_Name::Set(doc->GetData()->Root(), argv[1]); + Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc); + Draw::Set(argv[1], DD); + // di << "Document saved with name " << argv[1]; + } + if (!reader.Transfer(doc)) { + di << "Cannot read any relevant data from the STEP file\n"; + return 1; + } + + Handle(DDocStd_DrawDocument) DD = new DDocStd_DrawDocument(doc); + Draw::Set(argv[1], DD); + di << "Document saved with name " << argv[1]; + + NCollection_DataMap DicFile = reader.ExternFiles(); + FillDicWS(DicFile); + AddWS(fnom, XSDRAW::Session()); + + return 0; + +} void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) { @@ -537,4 +620,6 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) di.Add("XExpand", "XExpand Doc recursively(0/1) or XExpand Doc recursively(0/1) label1 abel2 ..." "or XExpand Doc recursively(0/1) shape1 shape2 ...",__FILE__, Expand, g); + di.Add("TestStep", "Doc filename: Read STEP file to DECAF document", __FILE__, testSTEP, g); + } diff --git a/src/XSDRAWSTEP/XSDRAWSTEP.cxx b/src/XSDRAWSTEP/XSDRAWSTEP.cxx index 07d260b934..131bd6a129 100644 --- a/src/XSDRAWSTEP/XSDRAWSTEP.cxx +++ b/src/XSDRAWSTEP/XSDRAWSTEP.cxx @@ -49,6 +49,8 @@ #include #include #include +#include +#include #include // Pour le transfert (write) @@ -272,26 +274,75 @@ static Standard_Integer stepread (Draw_Interpretor& di/*theCommands*/, Standard_ //======================================================================= static Standard_Integer testread (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { - if (argc != 3) + 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_Reader Reader; - Standard_CString filename = argv[1]; - IFSelect_ReturnStatus readstat = Reader.ReadFile(filename); - di<<"Status from reading STEP file "<NbEntities(); + //di<<"Number of entities : "<NbEntities(); + /* di<<"Sum number of entities : "<