From: jfa Date: Fri, 27 Aug 2010 11:48:04 +0000 (+0000) Subject: Mantis issue 0020750: IMP: Naming during STEP import. X-Git-Tag: end_translate_resources_09Jul10~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=343553810e8354c7951ccfa0ad2da63bd4f7095f;p=modules%2Fgeom.git Mantis issue 0020750: IMP: Naming during STEP import. --- diff --git a/src/GEOM/GEOM_Function.cxx b/src/GEOM/GEOM_Function.cxx index 0c048ffbe..46da48dfc 100644 --- a/src/GEOM/GEOM_Function.cxx +++ b/src/GEOM/GEOM_Function.cxx @@ -65,6 +65,7 @@ #define DESCRIPTION_LABEL 3 #define HISTORY_LABEL 4 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups +#define NAMING_LABEL 6 // 002020750: Naming during STEP import #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL)) #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition)) @@ -793,6 +794,16 @@ TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label& theArgu return aHistoryCurLabel; } +//============================================================================= +/*! + * GetNamingEntry + */ +//============================================================================= +TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create) +{ + return _label.FindChild(NAMING_LABEL, create); +} + //======================================================================= //function : GEOM_Function_Type_ //purpose : diff --git a/src/GEOM/GEOM_Function.hxx b/src/GEOM/GEOM_Function.hxx index a7eed17b5..9476ae2e6 100644 --- a/src/GEOM/GEOM_Function.hxx +++ b/src/GEOM/GEOM_Function.hxx @@ -269,10 +269,13 @@ public: Standard_EXPORT TDF_Label GetArgumentHistoryEntry (const TDF_Label& theArgumentRefEntry, const Standard_Boolean create = Standard_True); + //Returns top label of this function's naming tree + Standard_EXPORT TDF_Label GetNamingEntry (const Standard_Boolean create = Standard_True); + private: - TDF_Label _label; - bool _isDone; + TDF_Label _label; + bool _isDone; }; #endif diff --git a/src/GEOMImpl/GEOMImpl_ImportDriver.cxx b/src/GEOMImpl/GEOMImpl_ImportDriver.cxx index a4b0300f4..f28f5ea9d 100644 --- a/src/GEOMImpl/GEOMImpl_ImportDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ImportDriver.cxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -109,7 +108,7 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const // perform the import TCollection_AsciiString anError; - TopoDS_Shape aShape = fp( aFileName, aFormatName, anError, aFunction->GetEntry() ); + TopoDS_Shape aShape = fp(aFileName, aFormatName, anError, aFunction->GetNamingEntry()); // unload plugin library // commented by enk: @@ -159,7 +158,8 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_ImportDriver_Type_() //function : DownCast //purpose : //======================================================================= -const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(const Handle(Standard_Transient)& AnObject) +const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast + (const Handle(Standard_Transient)& AnObject) { Handle(GEOMImpl_ImportDriver) _anOtherObject; @@ -169,5 +169,5 @@ const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(cons } } - return _anOtherObject ; + return _anOtherObject; } diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 0b6a72d35..49292bda4 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -265,7 +265,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag()); //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName)); - // try to find existed name for current shape + // BEGIN: try to find existed name for current shape bool HasName = false; // recieve current TopoDS shape CORBA::String_var entry = aShape->GetEntry(); @@ -278,24 +278,28 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } entry = aMainSh->GetEntry(); Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry); - TDF_Label aMainLbl = anObj->GetEntry(); + TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry(); + // check all named shapes using iterator - TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True); - for(; anIt.More(); anIt.Next()) { + TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True); + + for (; anIt.More() && !HasName; anIt.Next()) { Handle(TNaming_NamedShape) anAttr = Handle(TNaming_NamedShape)::DownCast(anIt.Value()); - if(anAttr.IsNull()) continue; + if (anAttr.IsNull()) continue; TopoDS_Shape S = anAttr->Get(); - if( !S.IsEqual(TopoSh) ) continue; - TDF_Label L = anAttr->Label(); - Handle(TDataStd_Name) aName; - if(L.FindAttribute(TDataStd_Name::GetID(),aName)) { - aShapeName = aName->Get(); - HasName = true; + if (S.IsEqual(TopoSh)) { + TDF_Label L = anAttr->Label(); + Handle(TDataStd_Name) aName; + if (L.FindAttribute(TDataStd_Name::GetID(), aName)) { + aShapeName = aName->Get(); + HasName = true; + } } } + // END: try to find existed name for current shape - if(!HasName) { + if (!HasName) { // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number // of objects in the study, but compute a number of objects with the same prefix diff --git a/src/IGESImport/IGESImport.cxx b/src/IGESImport/IGESImport.cxx index 5e57079ad..a9ee6b7c6 100644 --- a/src/IGESImport/IGESImport.cxx +++ b/src/IGESImport/IGESImport.cxx @@ -22,7 +22,6 @@ // File: IGESImport.cxx // Created: Wed May 19 14:36:35 2004 // Author: Pavel TELKOV -// #include "utilities.h" @@ -31,15 +30,26 @@ #include #include #include +#include -#include -#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include +#include +#include #include #include #include -#include #ifdef WNT #if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS @@ -71,7 +81,7 @@ IGESIMPORT_EXPORT TopoDS_Shape Import (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, - const TDF_Label&) + const TDF_Label& theShapeLabel) { // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; @@ -84,19 +94,19 @@ IGESIMPORT_EXPORT if (status == IFSelect_RetDone) { - if( theFormatName == "IGES_UNIT" ) { - Handle(IGESData_IGESModel) aModel = + if (theFormatName == "IGES_UNIT") { + Handle(IGESData_IGESModel) aModel = Handle(IGESData_IGESModel)::DownCast(aReader.Model()); gp_Pnt P(1.0,0.0,0.0); - if(!aModel.IsNull()) { - Handle(TCollection_HAsciiString) aUnitName = + if (!aModel.IsNull()) { + Handle(TCollection_HAsciiString) aUnitName = aModel->GlobalSection().UnitName(); //cout<<"aUnitName = "<ToCString()<String()=="MM") { P = gp_Pnt(0.001,0.0,0.0); } - else if( aUnitName->String()=="CM" ) { + else if (aUnitName->String()=="CM") { P = gp_Pnt(0.01,0.0,0.0); } } @@ -106,12 +116,12 @@ IGESIMPORT_EXPORT aResShape = V; return aResShape; } - if( theFormatName == "IGES_SCALE" ) { + if (theFormatName == "IGES_SCALE") { //cout<<"need re-scale a model"<GlobalSection(); aGS.SetUnitFlag(6); aModel->SetGlobalSection(aGS); @@ -128,6 +138,38 @@ IGESIMPORT_EXPORT MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes()); aResShape = aReader.OneShape(); + // BEGIN: Store names of sub-shapes from file + Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); + Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); + if (!TR.IsNull()) { + Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess(); + Standard_Integer nb = Model->NbEntities(); + for (Standard_Integer i = 1; i <= nb; i++) { + Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i)); + if (ent.IsNull() || ! ent->HasName()) continue; + + // find target shape + Handle(Transfer_Binder) binder = TP->Find(ent); + if (binder.IsNull()) continue; + TopoDS_Shape S = TransferBRep::ShapeResult(binder); + if (S.IsNull()) continue; + + // create label and set shape + TDF_Label L; + TDF_TagSource aTag; + L = aTag.NewChild(theShapeLabel); + TNaming_Builder tnBuild (L); + tnBuild.Generated(S); + + // set a name + TCollection_AsciiString string = ent->NameValue()->String(); + string.LeftAdjust(); + string.RightAdjust(); + TCollection_ExtendedString str (string); + TDataStd_Name::Set(L, str); + } + } + // END: Store names } else { // switch (status) { // case IFSelect_RetVoid: diff --git a/src/IGESImport/Makefile.am b/src/IGESImport/Makefile.am index 3f3b3815d..1db39a774 100644 --- a/src/IGESImport/Makefile.am +++ b/src/IGESImport/Makefile.am @@ -16,13 +16,12 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # - # File : Makefile.in # Author : Pavel TELKOV # Modified by : Alexander BORODIN (OCN) - autotools usage # Module : GEOM # $Header$ -# + include $(top_srcdir)/adm_local/unix/make_common_starter.am # Libraries targets @@ -37,7 +36,7 @@ libIGESImport_la_CPPFLAGS = \ $(CAS_CPPFLAGS) \ $(KERNEL_CXXFLAGS) -libIGESImport_la_LDFLAGS = \ - $(STDLIB) \ - $(CAS_LDPATH) -lTKIGES \ +libIGESImport_la_LDFLAGS = \ + $(STDLIB) \ + $(CAS_LDPATH) -lTKIGES -lTKCAF \ $(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics diff --git a/src/STEPImport/Makefile.am b/src/STEPImport/Makefile.am index 6a912182e..e2bc83e37 100644 --- a/src/STEPImport/Makefile.am +++ b/src/STEPImport/Makefile.am @@ -43,4 +43,4 @@ libSTEPImport_la_CPPFLAGS = \ libSTEPImport_la_LDFLAGS = \ $(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics \ $(STDLIB) \ - $(CAS_LDPATH) -lTKSTEP + $(CAS_LDPATH) -lTKSTEP -lTKCAF diff --git a/src/STEPImport/STEPImport.cxx b/src/STEPImport/STEPImport.cxx index e6819dcb2..0ba785429 100644 --- a/src/STEPImport/STEPImport.cxx +++ b/src/STEPImport/STEPImport.cxx @@ -19,12 +19,10 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File: STEPImport.cxx +// Created: Wed May 19 14:41:10 2004 +// Author: Pavel TELKOV -// File: STEPImport.cxx -// Created: Wed May 19 14:41:10 2004 -// Author: Pavel TELKOV -// -// #include "utilities.h" #include @@ -34,13 +32,31 @@ #include #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include #include #include #include #include +#include #include +#include +#include +#include +#include + #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -70,11 +86,11 @@ extern "C" { -STEPIMPORT_EXPORT + STEPIMPORT_EXPORT TopoDS_Shape Import (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& /*theFormatName*/, TCollection_AsciiString& theError, - const TDF_Label&) + const TDF_Label& theShapeLabel) { MESSAGE("Import STEP model from file " << theFileName.ToCString()); // Set "C" numeric locale to save numbers correctly @@ -87,7 +103,7 @@ STEPIMPORT_EXPORT //VRV: OCC 4.0 migration TopoDS_Compound compound; BRep_Builder B; - B.MakeCompound( compound ); + B.MakeCompound(compound); try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; @@ -95,13 +111,13 @@ STEPIMPORT_EXPORT IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { - Standard_Boolean failsonly = Standard_False ; - aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity); + Standard_Boolean failsonly = Standard_False; + aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity); /* Root transfers */ Standard_Integer nbr = aReader.NbRootsForTransfer(); - aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity); + aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity); - for ( Standard_Integer n=1; n <= nbr; n++) { + for (Standard_Integer n = 1; n <= nbr; n++) { Standard_Boolean ok = aReader.TransferRoot(n); /* Collecting resulting entities */ Standard_Integer nbs = aReader.NbShapes(); @@ -116,22 +132,76 @@ STEPIMPORT_EXPORT break; } - for ( Standard_Integer i=1; i<=nbs; i++ ) { + for (Standard_Integer i = 1; i <= nbs; i++) { TopoDS_Shape aShape = aReader.Shape(i); - if ( aShape.IsNull() ) { + if (aShape.IsNull()) { // THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ; //return aResShape; continue; } else { - B.Add( compound, aShape ) ; + B.Add(compound, aShape); } } } - if ( aResShape.IsNull() ) + if (aResShape.IsNull()) aResShape = compound; - } else { + // BEGIN: Store names of sub-shapes from file + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aResShape, anIndices); + + Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); + Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); + if (!TR.IsNull()) { + Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); + Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition); + + Standard_Integer nb = Model->NbEntities(); + for (Standard_Integer ie = 1; ie <= nb; ie++) { + Handle(Standard_Transient) enti = Model->Value(ie); + if (enti->DynamicType() != tPD) continue; + + Handle(StepBasic_ProductDefinition) PD = + Handle(StepBasic_ProductDefinition)::DownCast(enti); + if (PD.IsNull()) continue; + + Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct(); + if (Prod->Name()->UsefullLength() <= 0) continue; + + Handle(TCollection_HAsciiString) aName = Prod->Name(); + TCollection_ExtendedString aNameExt (aName->ToCString()); + + // find target shape + Handle(Transfer_Binder) binder = TP->Find(enti); + if (binder.IsNull()) continue; + TopoDS_Shape S = TransferBRep::ShapeResult(binder); + if (S.IsNull()) continue; + + // as PRODUCT can be included in the main shape + // several times, we look here for all iclusions. + Standard_Integer isub, nbSubs = anIndices.Extent(); + for (isub = 1; isub <= nbSubs; isub++) + { + TopoDS_Shape aSub = anIndices.FindKey(isub); + if (aSub.IsPartner(S)) { + // create label and set shape + TDF_Label L; + TDF_TagSource aTag; + L = aTag.NewChild(theShapeLabel); + TNaming_Builder tnBuild (L); + //tnBuild.Generated(S); + tnBuild.Generated(aSub); + + // set a name + TDataStd_Name::Set(L, aNameExt); + } + } + } + } + // END: Store names + } + else { // switch (status) { // case IFSelect_RetVoid: // theError = "Nothing created or No data to process";