]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
For improvements 20019 and 20324.
authorskl <skl@opencascade.com>
Wed, 3 Jun 2009 07:39:16 +0000 (07:39 +0000)
committerskl <skl@opencascade.com>
Wed, 3 Jun 2009 07:39:16 +0000 (07:39 +0000)
12 files changed:
src/BREPImport/BREPImport.cxx
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
src/GEOMImpl/GEOMImpl_ImportDriver.cxx
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOM_I/GEOM_Gen_i.cc
src/GEOM_I/GEOM_Gen_i.hh
src/GEOM_I/GEOM_IInsertOperations_i.cc
src/GEOM_I_Superv/GEOM_Superv_i.cc
src/GEOM_I_Superv/GEOM_Superv_i.hh
src/GEOM_SWIG/geompyDC.py
src/IGESImport/IGESImport.cxx
src/STEPImport/STEPImport.cxx

index c34ae95fbe30ac8248bfe61746b0a9d70b1b364f..79cc2b648fcb03d8c6fe1a69ecaf21dad405080b 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TDF_Label.hxx>
 
 #ifdef WNT
  #if defined BREPIMPORT_EXPORTS || defined BREPImport_EXPORTS
@@ -61,7 +62,8 @@ extern "C"
 BREPIMPORT_EXPORT
   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
                        const TCollection_AsciiString& /*theFormatName*/,
-                       TCollection_AsciiString&       theError)
+                       TCollection_AsciiString&       theError,
+                      const TDF_Label&)
   {
     MESSAGE("Import BREP from file " << theFileName);
     TopoDS_Shape aShape;
index 5fb461ff7d4e13310675a14bab77cac0d4682737..102ebba74e2438d4f4918c9c73a8746c06a1b7e6 100644 (file)
 
 #include <GEOMImpl_Types.hxx>
 
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <BRep_Tool.hxx>
+#include <gp_Pnt.hxx>
+
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
@@ -206,7 +211,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
   if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result;
 
   Handle(TCollection_HAsciiString) aHLibName;
-  if (!IsSupported(Standard_True, theFormatName, aHLibName)) {
+  if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) {
     return result;
   }
   TCollection_AsciiString aLibName = aHLibName->String();
@@ -216,6 +221,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
   aCI.SetFileName(theFileName);
   aCI.SetFormatName(theFormatName);
   aCI.SetPluginName(aLibName);
+  //cout<<"IIO: theFormatName = "<<theFormatName.ToCString()<<endl;
 
   //Perform the Import
   try {
@@ -238,6 +244,21 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
     << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
 
   SetErrorCode(OK);
+
+  if( theFormatName == "IGES_UNIT" ) {
+    TopoDS_Shape S = aFunction->GetValue();
+    TopoDS_Vertex V = TopoDS::Vertex(S);
+    gp_Pnt P = BRep_Tool::Pnt(V);
+    double scale = P.X();
+    TCollection_AsciiString aUnitName = "UNIT_M";
+    if( fabs(scale-0.01) < 1.e-6 )
+      aUnitName = "UNIT_CM";
+    else if( fabs(scale-0.001) < 1.e-6 )
+      aUnitName = "UNIT_MM";
+    //cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
+    SetErrorCode(aUnitName);
+  }
+
   return result;
 }
 
@@ -411,7 +432,6 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
   if (isImport) aMode = "Import";
   else aMode = "Export";
 
-  
   // Read supported formats for the certain mode from install directory
   if (myResMgr->Find(aMode.ToCString())) {
     TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
index 4a309a0b67cbe59611416787defa8dd0edd980d7..0118c7514ade3fa74d5d5b46dea8b4a5208043a5 100644 (file)
@@ -53,7 +53,8 @@
 
 typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&,
                                   const TCollection_AsciiString&,
-                                  TCollection_AsciiString&);
+                                  TCollection_AsciiString&,
+                                 const TDF_Label&);
 
 //=======================================================================
 //function : GetID
@@ -100,14 +101,14 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
     fp = (funcPoint)GetProc( anImportLib, "Import" );
 
   if ( !fp ) {
-    TCollection_AsciiString aMsg = aFormatName;
+    TCollection_AsciiString aMsg = aFormatName.SubString(1,4);
     aMsg += " plugin was not installed";
     Standard_Failure::Raise(aMsg.ToCString());
   }
 
   // perform the import
   TCollection_AsciiString anError;
-  TopoDS_Shape aShape = fp( aFileName, aFormatName, anError );
+  TopoDS_Shape aShape = fp( aFileName, aFormatName, anError, aFunction->GetEntry() );
 
   // unload plugin library
   // commented by enk:
index 4945b72e8406b7fced6c0fb982cea49eac02d761..c3556b63837a31dcea361452deb024b55a4b8deb 100644 (file)
@@ -694,6 +694,7 @@ bool GEOMToolsGUI::Import()
       continue;
     }
 
+
     GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
     try {
       app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
@@ -701,6 +702,26 @@ bool GEOMToolsGUI::Import()
 
       CORBA::String_var fileN = fileName.toLatin1().constData();
       CORBA::String_var fileT = aCurrentType.toLatin1().constData();
+
+      // skl 29.05.2009
+      if( aCurrentType == "IGES" ) {
+       GEOM::GEOM_Object_var anObj = aInsOp->Import( fileN, "IGES_UNIT" );
+       TCollection_AsciiString aUnitName = aInsOp->GetErrorCode();
+       //cout<<"GUI: aUnitName = "<<aUnitName.ToCString()<<endl;
+       if( aUnitName.SubString(1,4) == "UNIT" ) {
+         aUnitName = aUnitName.SubString(6,aUnitName.Length());
+         if( aUnitName != "M" ) {
+           if( SUIT_MessageBox::question( app->desktop(),
+                                          "Question",//tr("WRN_WARNING"),
+                                          "Length unit in given file is not a 'meter'. Is it needed to scale a model?",
+                                          SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+                                          SUIT_MessageBox::No) == SUIT_MessageBox::Yes ) {
+             fileT = "IGES_SCALE";
+           }
+         }
+       }
+      }
+
       GEOM::GEOM_Object_var anObj = aInsOp->Import( fileN, fileT );
 
       if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
@@ -715,6 +736,16 @@ bool GEOMToolsGUI::Import()
 
        objsForDisplay.append( anObj );
        
+       if( aCurrentType == "ACIS" ) {
+         if( SUIT_MessageBox::question( app->desktop(),
+                                        "Question",//tr("WRN_WARNING"),
+                                        "Given file contents some names. Is it needed to create groups for named shapes?",
+                                        SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+                                        SUIT_MessageBox::No) == SUIT_MessageBox::Yes ) {
+           GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy(aDSStudy, anObj);
+         }
+       }
+
        anOp->commit();
       }
       else {
index 7f9f5cab49ba11e64d867dc1e0e6d548276c57b9..2758bf025248dfba8dc1af4ba6f1709adf0ddb86 100644 (file)
@@ -39,6 +39,7 @@
 #include "GEOM_Object_i.hh"
 #include "GEOM_Object.hxx"
 #include "GEOM_Function.hxx"
+#include "GEOM_ISubShape.hxx"
 #include "GEOMImpl_Types.hxx"
 #include "GEOMImpl_CopyDriver.hxx"
 
 #include <BRepTools.hxx>
 #include <TDF_Label.hxx>
 #include <TDF_Tool.hxx>
+#include <TDF_ChildIDIterator.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TDataStd_Name.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_HArray1OfInteger.hxx>
 #include <TopAbs_ShapeEnum.hxx>
+//#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopExp.hxx>
 #include <OSD.hxx>
 
 #include "SALOMEDS_Tool.hxx"
@@ -248,24 +254,57 @@ 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
+  bool HasName = false;
+  // recieve current TopoDS shape
+  CORBA::String_var entry = aShape->GetEntry();
+  Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
+  TopoDS_Shape TopoSh = aGShape->GetValue();
+  // find label of main shape
+  GEOM::GEOM_Object_var aMainShVar = aShape;
+  GEOM::GEOM_Object_ptr aMainSh = aMainShVar._retn();
+  while( !aMainSh->IsMainShape() ) {
+    aMainSh = aMainSh->GetMainShape();
+  }
+  entry = aMainSh->GetEntry();
+  Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
+  TDF_Label aMainLbl = anObj->GetEntry();
+  // check all named shapes using iterator
+  TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
+  for(; anIt.More(); anIt.Next()) {
+    Handle(TNaming_NamedShape) anAttr =
+      Handle(TNaming_NamedShape)::DownCast(anIt.Value());
+    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;
+    }
+  }
 
-  // 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
-  //       and build a new name as Prefix_N+1
-  if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
-    int i = 0;                    // (WITH EMPTY NEW NAME)
-    SALOMEDS::SObject_var obj;
-    TCollection_AsciiString aNewShapeName;
-    do {
-      aNewShapeName = aShapeName + TCollection_AsciiString(++i);
-      obj = theStudy->FindObject( aNewShapeName.ToCString() );
+  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
+    //       and build a new name as Prefix_N+1
+    if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
+      int i = 0;                    // (WITH EMPTY NEW NAME)
+      SALOMEDS::SObject_var obj;
+      TCollection_AsciiString aNewShapeName;
+      do {
+       aNewShapeName = aShapeName + TCollection_AsciiString(++i);
+       obj = theStudy->FindObject( aNewShapeName.ToCString() );
+      }
+      while ( !obj->_is_nil() );
+      aShapeName = aNewShapeName;
     }
-    while ( !obj->_is_nil() );
-    aShapeName = aNewShapeName;
+    else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
+      aShapeName = TCollection_AsciiString((char*)theName);
   }
-  else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
-    aShapeName = TCollection_AsciiString((char*)theName);
 
   //Set the study entry as a name of  the published GEOM_Object
   aShape->SetStudyEntry(aResultSO->GetID());
@@ -300,6 +339,126 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
 }
 
 
+//============================================================================
+// function : CreateAndPublishGroup
+// purpose  : auxilary for PublishNamedShapesInStudy
+//============================================================================
+void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
+                                      GEOM::GEOM_Object_var theMainShape,
+                                      const TopTools_IndexedMapOfShape& anIndices,
+                                      const TopTools_SequenceOfShape& SeqS,
+                                      const TColStd_SequenceOfAsciiString& SeqN,
+                                      const Standard_CString& GrName,
+                                      GEOM::ListOfGO_var aResList)
+{
+  CORBA::String_var entry = theMainShape->GetEntry();
+  Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
+  Handle(TColStd_HArray1OfInteger) anArray;
+  if(SeqS.Length()>0) {
+    // create a group
+    GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
+    GEOM::GEOM_Object_ptr GrObj =
+      GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
+    AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
+    // add named objects
+    Handle(GEOM_Object) anObj;
+    for(int i=1; i<=SeqS.Length(); i++) {
+      TopoDS_Shape aValue = SeqS.Value(i);
+      anArray = new TColStd_HArray1OfInteger(1,1);
+      Standard_Integer anIndex = anIndices.FindIndex(aValue);
+      anArray->SetValue(1, anIndex);
+      anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
+      if (anObj.IsNull()) continue;
+      Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
+      if (aFunction.IsNull()) continue;
+      GEOM_ISubShape aSSI(aFunction);
+      aSSI.SetMainShape(aMainShape->GetLastFunction());
+      aSSI.SetIndices(anArray);
+      aFunction->SetValue(aValue);
+      GOp->UnionIDs(GrObj, anIndex);
+      SALOMEDS::SObject_var aResultSO;
+      TCollection_AsciiString anEntry;
+      TDF_Tool::Entry(anObj->GetEntry(),anEntry);
+      GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
+      AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
+    }
+  }
+}
+
+
+//============================================================================
+// function : PublishNamedShapesInStudy
+// purpose  :
+//============================================================================
+GEOM::ListOfGO* GEOM_Gen_i::
+            PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
+                                     //SALOMEDS::SObject_ptr theSObject,
+                                     CORBA::Object_ptr theObject)
+{
+  //Unexpect aCatch(SALOME_SalomeException);
+  GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
+
+  //CORBA::Object_var theObject = theSObject->GetObject();
+  GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
+  if(theMainShape->_is_nil()) return aResList._retn();
+
+  CORBA::String_var entry = theMainShape->GetEntry();
+  Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
+  if (aMainShape.IsNull()) return aResList._retn();
+  TopoDS_Shape MainSh = aMainShape->GetValue();
+
+  TDF_Label aMainLbl = aMainShape->GetEntry();
+  TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
+  TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
+  TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
+  for(; anIt.More(); anIt.Next()) {
+    Handle(TNaming_NamedShape) anAttr =
+      Handle(TNaming_NamedShape)::DownCast(anIt.Value());
+    if(anAttr.IsNull()) continue;
+    TopoDS_Shape S = anAttr->Get();
+    TDF_Label L = anAttr->Label();
+    //if(S.IsEqual(MainSh)) continue;
+    Handle(TDataStd_Name) aName;
+    if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
+      TCollection_ExtendedString EName = aName->Get();
+      if(S.ShapeType()==TopAbs_SOLID) {
+       SolidSeqS.Append(S);
+       SolidSeqN.Append(aName->Get());
+      }
+      else if(S.ShapeType()==TopAbs_FACE) {
+       FaceSeqS.Append(S);
+       FaceSeqN.Append(aName->Get());
+      }
+      else if(S.ShapeType()==TopAbs_EDGE) {
+       EdgeSeqS.Append(S);
+       EdgeSeqN.Append(aName->Get());
+      }
+      else if(S.ShapeType()==TopAbs_VERTEX) {
+       VertSeqS.Append(S);
+       VertSeqN.Append(aName->Get());
+      }
+    }
+  }
+
+  TopTools_IndexedMapOfShape anIndices;
+  TopExp::MapShapes(MainSh, anIndices);
+
+  CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
+                       "Group_Of_Named_Solids", aResList);
+
+  CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
+                       "Group_Of_Named_Faces", aResList);
+
+  CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
+                       "Group_Of_Named_Edges", aResList);
+
+  CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
+                       "Group_Of_Named_Vertices", aResList);
+
+  return aResList._retn();
+}
+
+
 //============================================================================
 // function : Save()
 // purpose  : save OCAF/Geom document
index aba3b6aa665cff56ee15f7eb15cc8f0d4fe76778..75b56384fcdc967d3a07fd048fb269c348054fe8 100644 (file)
@@ -50,6 +50,8 @@
 #include "GEOM_IMeasureOperations_i.hh"
 #include "GEOM_IGroupOperations_i.hh"
 
+#include <TopTools_IndexedMapOfShape.hxx>
+
 //#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 
@@ -120,6 +122,9 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi
                                       CORBA::Object_ptr theObject,
                                       const char* theName) throw (SALOME::SALOME_Exception) ;
 
+  GEOM::ListOfGO* PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
+                                           CORBA::Object_ptr theObject);
+
   CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject);
   SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID);
   CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID);
@@ -257,6 +262,15 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi
                                   GEOM::find_shape_method theFindMethod,
                                   CORBA::Boolean          theInheritFirstArg);
 
+  // auxilary for PublishNamedShapesInStudy
+  void CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
+                            GEOM::GEOM_Object_var theMainShape,
+                            const TopTools_IndexedMapOfShape& anIndices,
+                            const TopTools_SequenceOfShape& SeqS,
+                            const TColStd_SequenceOfAsciiString& SeqN,
+                            const Standard_CString& GrName,
+                            GEOM::ListOfGO_var aResList);
+
  private:
 
    ::GEOMImpl_Gen* _impl;
index 832b8df27bef26cff4f9a431d582e4f64e2ac2c5..b32b3eb717457407857f29ab3b4e210d04ab90ff 100644 (file)
@@ -129,11 +129,19 @@ GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
   char* aFileName   = strdup(theFileName);
   char* aFormatName = strdup(theFormatName);
   Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
+
+  if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
+    free(aFileName);
+    free(aFormatName);
+    return GetObject(anObject);
+  }
+
   free(aFileName);
   free(aFormatName);
 
-  if (!GetOperations()->IsDone() || anObject.IsNull())
+  if (!GetOperations()->IsDone() || anObject.IsNull()) {
     return aGEOMObject._retn();
+  }
 
   return GetObject(anObject);
 }
index a5e8efb38c80547e1a38aee3f7f8124791a85bcb..f749b86412baffd9a17fde301d1b2824dbb8ce44 100644 (file)
@@ -473,6 +473,20 @@ SALOMEDS::SObject_ptr GEOM_Superv_i::PublishInStudy(SALOMEDS::Study_ptr theStudy
   return myGeomEngine->PublishInStudy(theStudy, theSObject, theObject, theName);
 }
 
+//============================================================================
+// function : PublishNamedShapesInStudy
+// purpose  : 
+//============================================================================
+GEOM::ListOfGO*
+GEOM_Superv_i::PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
+                                        //SALOMEDS::SObject_ptr theSObject,
+                                        CORBA::Object_ptr theObject)
+{
+  if (CORBA::is_nil(myGeomEngine))
+    setGeomEngine();
+  return myGeomEngine->PublishNamedShapesInStudy(theStudy, theObject);
+}
+
 //============================================================================
 // function : CanCopy()
 // purpose  :
index da63e23662dd924b85c8e68dcbd4cd958019f71d..1568f0bb15a81b4eaf6fc98399a3f882f018c417 100644 (file)
@@ -125,6 +125,10 @@ public:
                                       CORBA::Object_ptr theObject,
                                       const char* theName) throw (SALOME::SALOME_Exception) ;
 
+  GEOM::ListOfGO* PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
+                                           //SALOMEDS::SObject_ptr theSObject,
+                                           CORBA::Object_ptr theObject);
+
   CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject);
   SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID);
   CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID);
index eac732fd843f10d75c6c86d97c95aab7ac857d12..1cf7bd07f8b861559417621ca21f8efe1648e86a 100644 (file)
@@ -3204,6 +3204,8 @@ class geompyDC(GEOM._objref_GEOM_Gen):
         #  @param theFileName The file, containing the shape.
         #  @param theFormatName Specify format for the file reading.
         #         Available formats can be obtained with InsertOp.ImportTranslators() method.
+        #         If format 'IGES_SCALE' is used instead 'IGES' length unit will be
+        #         set to 'meter' and result model will be scaled.
         #  @return New GEOM_Object, containing the imported shape.
         #
         #  @ref swig_Import_Export "Example"
@@ -3227,6 +3229,24 @@ class geompyDC(GEOM._objref_GEOM_Gen):
             # Example: see GEOM_TestOthers.py
             return self.Import(theFileName, "IGES")
 
+        ## Return length unit from given IGES file
+        #
+        #  @ref swig_Import_Export "Example"
+        def GetIGESUnit(self,theFileName):
+            # Example: see GEOM_TestOthers.py
+            anObj = self.InsertOp.Import(theFileName, "IGES_UNIT")
+            #RaiseIfFailed("Import", self.InsertOp)
+            # recieve name using returned vertex
+            UnitName = "M"
+            vertices = self.SubShapeAll(anObj,ShapeType["VERTEX"])
+            if len(vertices)>0:
+                p = self.PointCoordinates(vertices[0])
+                if abs(p[0]-0.01) < 1.e-6:
+                    UnitName = "CM"
+                elif abs(p[0]-0.001) < 1.e-6:
+                    UnitName = "MM"
+            return UnitName
+
         ## Shortcut to Import() for STEP format
         #
         #  @ref swig_Import_Export "Example"
index 51ed1ebe35490767bb2a60fd66cab4e9985ca3bb..fbbe1c9b438b2fdedeffd5a065e3c3c145925925 100644 (file)
 
 #include <IFSelect_ReturnStatus.hxx>
 #include <IGESControl_Reader.hxx>
+#include <IGESData_IGESModel.hxx>
 
-#include <TCollection_AsciiString.hxx>
+#include <TCollection_HAsciiString.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TDF_Label.hxx>
+
+#include <TopoDS_Vertex.hxx>
+#include <BRep_Builder.hxx>
+#include <gp_Pnt.hxx>
 
 #ifdef WNT
  #if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS
@@ -60,8 +66,9 @@ extern "C"
 {
 IGESIMPORT_EXPORT
   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
-                       const TCollection_AsciiString& /*theFormatName*/,
-                       TCollection_AsciiString&       theError)
+                       const TCollection_AsciiString& theFormatName,
+                       TCollection_AsciiString&       theError,
+                      const TDF_Label&)
   {
     IGESControl_Reader aReader;
     TopoDS_Shape aResShape;
@@ -69,6 +76,41 @@ IGESIMPORT_EXPORT
       IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
 
       if (status == IFSelect_RetDone) {
+
+       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 = 
+             aModel->GlobalSection().UnitName();
+           //cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
+           //cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
+           if( aUnitName->String()=="MM" ) {
+             P = gp_Pnt(0.001,0.0,0.0);
+           }
+           else if( aUnitName->String()=="CM" ) {
+             P = gp_Pnt(0.01,0.0,0.0);
+           }
+         }
+         BRep_Builder B;
+         TopoDS_Vertex V;
+         B.MakeVertex(V,P,1.e-7);
+         aResShape = V;
+         return aResShape;
+       }
+       if( theFormatName == "IGES_SCALE" ) {
+         //cout<<"need re-scale a model"<<endl;
+         // set UnitFlag to 'meter'
+         Handle(IGESData_IGESModel) aModel = 
+           Handle(IGESData_IGESModel)::DownCast(aReader.Model());
+         if(!aModel.IsNull()) {
+           IGESData_GlobalSection aGS = aModel->GlobalSection();
+           aGS.SetUnitFlag(6);
+           aModel->SetGlobalSection(aGS);
+         }
+       }
+
         MESSAGE("ImportIGES : all Geometry Transfer");
         //OCC 5.1.2 porting
         //     aReader.Clear();
index 4440aeb8767410560194664039cc9b08e23bbd70..33e15f5241e711233e462152d272fac4dec90624 100644 (file)
@@ -35,6 +35,7 @@
 #include <TCollection_AsciiString.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Shape.hxx>
+#include <TDF_Label.hxx>
 
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
@@ -68,7 +69,8 @@ extern "C"
 STEPIMPORT_EXPORT
   TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
                        const TCollection_AsciiString& /*theFormatName*/,
-                       TCollection_AsciiString&       theError)
+                       TCollection_AsciiString&       theError,
+                      const TDF_Label&)
   {
     MESSAGE("Import STEP model from file " << theFileName.ToCString());
     TopoDS_Shape aResShape;