]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Mantis issue 0020750: IMP: Naming during STEP import.
authorjfa <jfa@opencascade.com>
Fri, 27 Aug 2010 11:48:04 +0000 (11:48 +0000)
committerjfa <jfa@opencascade.com>
Fri, 27 Aug 2010 11:48:04 +0000 (11:48 +0000)
src/GEOM/GEOM_Function.cxx
src/GEOM/GEOM_Function.hxx
src/GEOMImpl/GEOMImpl_ImportDriver.cxx
src/GEOM_I/GEOM_Gen_i.cc
src/IGESImport/IGESImport.cxx
src/IGESImport/Makefile.am
src/STEPImport/Makefile.am
src/STEPImport/STEPImport.cxx

index 0c048ffbec79233deed0f6e1fbd22a47d0f56087..46da48dfc0b47a5b23b8dc6819fbf36b85bb7f4e 100644 (file)
@@ -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  :
index a7eed17b523d56e62d69e8256026deda876a645d..9476ae2e64a3f28a5f642be43755b5dec4a451fd 100644 (file)
@@ -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
index a4b0300f44d851bd948e3cbfc9e5bccf14fee137..f28f5ea9d37b380eefbf871ba495e8ba800c7b53 100644 (file)
@@ -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 <Standard_Stream.hxx>
 
@@ -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;
 }
index 0b6a72d35528bfeacd691406ec88a7b3a5bca307..49292bda414c14ae054eee9905e8585a2882508d 100644 (file)
@@ -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
index 5e57079adcb35f42d5cd16555bd7a392f8b48b64..a9ee6b7c65e498243401c297771bb0b0f0f4bc29 100644 (file)
@@ -22,7 +22,6 @@
 //  File:        IGESImport.cxx
 //  Created:     Wed May 19 14:36:35 2004
 //  Author:      Pavel TELKOV
-//               <ptv@mutex.nnov.opencascade.com>
 
 #include "utilities.h"
 
 #include <IFSelect_ReturnStatus.hxx>
 #include <IGESControl_Reader.hxx>
 #include <IGESData_IGESModel.hxx>
+#include <IGESData_IGESEntity.hxx>
 
-#include <TCollection_HAsciiString.hxx>
-#include <TopoDS_Shape.hxx>
+#include <Interface_Static.hxx>
+#include <Interface_InterfaceModel.hxx>
+#include <XSControl_TransferReader.hxx>
+#include <XSControl_WorkSession.hxx>
+#include <Transfer_TransientProcess.hxx>
+#include <Transfer_Binder.hxx>
+#include <TransferBRep.hxx>
+
+#include <TNaming_Builder.hxx>
+#include <TDF_TagSource.hxx>
+#include <TDataStd_Name.hxx>
 #include <TDF_Label.hxx>
 
+#include <TCollection_HAsciiString.hxx>
+#include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Builder.hxx>
 #include <gp_Pnt.hxx>
-#include <Interface_Static.hxx>
 
 #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 = "<<aUnitName->ToCString()<<endl;
             //cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
-            if( aUnitName->String()=="MM" ) {
+            if (aUnitName->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"<<endl;
           // set UnitFlag to 'meter'
-          Handle(IGESData_IGESModel) aModel = 
+          Handle(IGESData_IGESModel) aModel =
             Handle(IGESData_IGESModel)::DownCast(aReader.Model());
-          if(!aModel.IsNull()) {
+          if (!aModel.IsNull()) {
             IGESData_GlobalSection aGS = aModel->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:
index 3f3b3815d8f725e077672e6854f0618af8d0dd98..1db39a7741da4e5cc993734565b984a2df1b6d38 100644 (file)
 #
 #  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
index 6a912182e6b1b0b1e087a2a2c94ff0d16908d800..e2bc83e3702fac4106c03e7524378587bd5a8daf 100644 (file)
@@ -43,4 +43,4 @@ libSTEPImport_la_CPPFLAGS =   \
 libSTEPImport_la_LDFLAGS  =                    \
        $(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics \
        $(STDLIB)                               \
-       $(CAS_LDPATH) -lTKSTEP
+       $(CAS_LDPATH) -lTKSTEP -lTKCAF
index e6819dcb2e0a2c5600b2fdf22adee4603ef6a7b5..0ba7854298f0b8acd5fcb5f649b6394255784b1a 100644 (file)
 //
 //  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
-//              <ptv@mutex.nnov.opencascade.com>
-//
 #include "utilities.h"
 
 #include <Basics_Utils.hxx>
 #include <IFSelect_ReturnStatus.hxx>
 
 #include <STEPControl_Reader.hxx>
+#include <StepBasic_ProductDefinition.hxx>
+#include <StepBasic_ProductDefinitionFormation.hxx>
+#include <StepBasic_Product.hxx>
+#include <Interface_InterfaceModel.hxx>
+#include <XSControl_TransferReader.hxx>
+#include <XSControl_WorkSession.hxx>
+
+#include <Transfer_Binder.hxx>
+#include <TNaming_Builder.hxx>
+#include <TDataStd_Name.hxx>
+#include <Transfer_TransientProcess.hxx>
+#include <TransferBRep.hxx>
 
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TDF_Label.hxx>
+#include <TDF_Tool.hxx>
 #include <Interface_Static.hxx>
 
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopExp.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <BRepTools.hxx>
+
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 
 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";