]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Fix crash of BugRevolution.py import
authorjfa <jfa@opencascade.com>
Tue, 2 Aug 2005 06:55:46 +0000 (06:55 +0000)
committerjfa <jfa@opencascade.com>
Tue, 2 Aug 2005 06:55:46 +0000 (06:55 +0000)
src/GEOMGUI/GeometryGUI_Swig.cxx

index 6622311584c698c347084e2d70f6b7f4efde331f..9c1ef575f359d90d3b6723aede515f6728116e8c 100644 (file)
@@ -1,23 +1,23 @@
 //  GEOM GEOMGUI : GUI for Geometry component
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //
 //  $Header$
 
 #include "GeometryGUI_Swig.hxx"
+
+#include "GEOM_Actor.h"
+#include "GEOM_Client.hxx"
+#include "GEOM_AISShape.hxx"
+#include "GEOM_AssemblyBuilder.h"
+#include "GEOM_InteractiveObject.hxx"
+
 #include "SALOMEGUI_Swig.hxx"
 
 #include "QAD_Application.h"
 #include "QAD_RightFrame.h"
 #include "SALOMEGUI_ImportOperation.h"
 
+#include "SALOME_Event.hxx"
+
 #include "OCCViewer_Viewer3d.h"
 #include "OCCViewer_ViewFrame.h"
+
+#include "VTKViewer_RenderWindowInteractor.h"
+#include "VTKViewer_ViewFrame.h"
+
+#include "utilities.h"
+
+// OCCT Includes
 #include <TopExp_Explorer.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <V3d_Viewer.hxx>
 
-#include "SALOME_Event.hxx"
-
-#include "VTKViewer_RenderWindowInteractor.h"
-#include "VTKViewer_ViewFrame.h"
-
-#include "GEOM_Actor.h"
-#include "GEOM_Client.hxx"
-#include "GEOM_AISShape.hxx"
-#include "GEOM_AssemblyBuilder.h"
-#include "GEOM_InteractiveObject.hxx"
-
-#include "utilities.h"
-
 using namespace std;
 
 static GEOM_Client ShapeReader;
@@ -87,93 +90,93 @@ GEOM_Swig::~GEOM_Swig()
   // MESSAGE("Destructeur");
 }
 
-void GEOM_Swig::createAndDisplayGO(const char* Entry)
+void GEOM_Swig::createAndDisplayGO (const char* Entry)
 {
-  // MESSAGE("createAndDisplayGO");
-  QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
-  SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
-  SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
-
-  Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
-  GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
-
-  CORBA::String_var aFatherIOR;
-  SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
-  aStudyBuilder->DefineComponentInstance( father, Geom );
-  father->ComponentIOR(aFatherIOR);
-
-  SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
-
-  SALOMEDS::SObject_var obj = aStudy->FindObjectID(Entry);
-  SALOMEDS::GenericAttribute_var anAttr;
-  SALOMEDS::AttributeIOR_var     anIOR;
-  // Create new actor
-  if ( !obj->FindAttribute(anAttr, "AttributeIOR")) 
-    return;
-  anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-  CORBA::String_var anIORValue = anIOR->Value();
-  
-  GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue);
-  TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
-  
-  if ( !obj->_is_nil() ) {
-    if (obj->FindAttribute(anAttr, "AttributeName")) {
-      SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      CORBA::String_var aNameValue = aName->Value();
-      // open transaction
-      QAD_Operation* op = new SALOMEGUI_ImportOperation( ActiveStudy );
-      op->start();
-      
-      SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
-      aStudyBuilder->Addreference(newObj1, obj);
-      // commit transaction
-      op->finish();
-                 
-      Handle(GEOM_InteractiveObject) anIO = new GEOM_InteractiveObject(const_cast<char*>(anIORValue.in()),
-                                                                      const_cast<char*>(aFatherIOR.in()),
-                                                                      "GEOM",
-                                                                      const_cast<char*>(obj->GetID()));
-      
-      class TEvent: public SALOME_Event{
-        QAD_Study* myStudy;
-        TopoDS_Shape myShape;
-        Handle(SALOME_InteractiveObject) myIO;
-        const char* myName;
-      public:
-        TEvent(QAD_Study* theStudy, TopoDS_Shape theShape,
-              const Handle(SALOME_InteractiveObject)& theIO, 
-              const char* theName):
-         myStudy(theStudy), myShape(theShape),
-                                  myIO(theIO), myName(theName)
-        {}
-        virtual void Execute(){
-         if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
-           VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
-           int aMode = myRenderInter->GetDisplayMode();
-           
-           vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(myShape,0,aMode,true);
+  class TEvent: public SALOME_Event
+  {
+    std::string myEntry;
+  public:
+    TEvent(const char* theEntry):
+      myEntry(theEntry)
+    {}
+    virtual void Execute()
+    {
+      QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
+      SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
+      SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+
+      Engines::Component_var comp =
+        QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
+      GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
+
+      CORBA::String_var aFatherIOR;
+      SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
+      aStudyBuilder->DefineComponentInstance(father, Geom);
+      father->ComponentIOR(aFatherIOR);
+
+      SALOMEDS::SObject_var fatherSF =
+        aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
+
+      SALOMEDS::SObject_var obj = aStudy->FindObjectID(myEntry.c_str());
+      SALOMEDS::GenericAttribute_var anAttr;
+      SALOMEDS::AttributeIOR_var     anIOR;
+      // Create new actor
+      if (!obj->FindAttribute(anAttr, "AttributeIOR"))
+        return;
+      anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
+      CORBA::String_var anIORValue = anIOR->Value();
+
+      GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue);
+      TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
+
+      if (!obj->_is_nil()) {
+        if (obj->FindAttribute(anAttr, "AttributeName")) {
+          SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
+          CORBA::String_var aNameValue = aName->Value();
+          // open transaction
+          QAD_Operation* op = new SALOMEGUI_ImportOperation (ActiveStudy);
+          op->start();
+
+          SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
+          aStudyBuilder->Addreference(newObj1, obj);
+          // commit transaction
+          op->finish();
+
+          Handle(GEOM_InteractiveObject) anIO =
+            new GEOM_InteractiveObject(const_cast<char*>(anIORValue.in()),
+                                       const_cast<char*>(aFatherIOR.in()),
+                                       "GEOM",
+                                       const_cast<char*>(obj->GetID()));
+
+         if (VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(ActiveStudy)) {
+           VTKViewer_RenderWindowInteractor* aRenderInter= aViewFrame->getRWInteractor();
+           int aMode = aRenderInter->GetDisplayMode();
+
+           vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape,0,aMode,true);
            theActors->InitTraversal();
-           while(vtkActor* anActor = theActors->GetNextActor()){
+           while (vtkActor* anActor = theActors->GetNextActor()) {
              GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
-             GActor->setName(const_cast<char*>(myName));
-             GActor->setIO(myIO);
-             myRenderInter->Display(GActor);
+             GActor->setName(const_cast<char*>(aNameValue.in()));
+             GActor->setIO(anIO);
+             aRenderInter->Display(GActor);
            }
-           myRenderInter->Update();
-         }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
+           aRenderInter->Update();
+         } else if (OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(ActiveStudy)) {
            Handle(AIS_InteractiveContext) ic = aViewFrame->getViewer()->getAISContext();
-           Handle(GEOM_AISShape) aSh = new GEOM_AISShape(myShape,const_cast<char*>(myName));
-           aSh->setName(const_cast<char*>(myName));
-           aSh->setIO(myIO);
+           Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape,const_cast<char*>(aNameValue.in()));
+           aSh->setName(const_cast<char*>(aNameValue.in()));
+           aSh->setIO(anIO);
            ic->Display(aSh);
            ic->AddOrRemoveCurrentObject(aSh,true);
          }
-         myStudy->updateObjBrowser(true);
+         ActiveStudy->updateObjBrowser(true);
         }
-      };
-      ProcessVoidEvent(new TEvent(ActiveStudy,Shape,anIO,aNameValue.in()));
+      }
     }
-  }
+  };
+
+  //MESSAGE("createAndDisplayGO");
+  ProcessVoidEvent(new TEvent (Entry));
 }
 
 
@@ -181,7 +184,7 @@ int  GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
 {
   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
   GEOM::GEOM_Gen_var  Geom = GEOM::GEOM_Gen::_narrow(comp);
+
   GEOM::GEOM_Object_var aMainShape = Geom->GetIORFromString(IOR);
   TopoDS_Shape shape = ShapeReader.GetShape(Geom, aMainShape);
 
@@ -189,35 +192,35 @@ int  GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
   TopoDS_Shape subshape = ShapeReader.GetShape(Geom, aSubShape);
 
   int index = 1;
-  if(subshape.ShapeType() == TopAbs_COMPOUND) { 
-    TopoDS_Iterator it; 
-    TopTools_ListOfShape CL; 
-    CL.Append(shape); 
-    TopTools_ListIteratorOfListOfShape itC; 
+  if(subshape.ShapeType() == TopAbs_COMPOUND) {
+    TopoDS_Iterator it;
+    TopTools_ListOfShape CL;
+    CL.Append(shape);
+    TopTools_ListIteratorOfListOfShape itC;
     for(itC.Initialize(CL); itC.More(); itC.Next()) {
-      for(it.Initialize(itC.Value()); it.More(); it.Next()) { 
+      for(it.Initialize(itC.Value()); it.More(); it.Next()) {
        if (it.Value().ShapeType() == TopAbs_COMPOUND) {
          if (it.Value().IsSame(subshape))
-           return index; 
-         else 
-           index++; 
-         CL.Append(it.Value()); 
+           return index;
+         else
+           index++;
+         CL.Append(it.Value());
        }
-      } 
-    } 
-  } 
-  else { 
-    TopExp_Explorer Exp(shape, subshape.ShapeType()); 
-    TopTools_MapOfShape M; 
-    while(Exp.More()) { 
+      }
+    }
+  }
+  else {
+    TopExp_Explorer Exp(shape, subshape.ShapeType());
+    TopTools_MapOfShape M;
+    while(Exp.More()) {
       if(M.Add(Exp.Current())) {
-       if(Exp.Current().IsSame(subshape)) 
-         return index; 
-       index++; 
-      } 
-      Exp.Next(); 
-    } 
-  } 
+       if(Exp.Current().IsSame(subshape))
+         return index;
+       index++;
+      }
+      Exp.Next();
+    }
+  }
   return -1;
 }
 
@@ -225,7 +228,7 @@ const char* GEOM_Swig::getShapeTypeString(const char* IOR)
 {
   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
   GEOM::GEOM_Gen_var  Geom = GEOM::GEOM_Gen::_narrow(comp);
+
   GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
   TopoDS_Shape shape    = ShapeReader.GetShape(Geom, aShape);
 
@@ -244,7 +247,7 @@ const char* GEOM_Swig::getShapeTypeString(const char* IOR)
   case TopAbs_SHELL:
     { return "Shell" ;}
   case TopAbs_FACE:
-    { 
+    {
       BRepAdaptor_Surface surf(TopoDS::Face(shape));
       if ( surf.GetType() == GeomAbs_Plane ) {
        return "Plane" ;
@@ -263,10 +266,10 @@ const char* GEOM_Swig::getShapeTypeString(const char* IOR)
   case TopAbs_WIRE:
     { return "Wire" ;}
   case TopAbs_EDGE:
-    { 
+    {
       BRepAdaptor_Curve curv(TopoDS::Edge(shape));
       if ( curv.GetType() == GeomAbs_Line ) {
-       if ( (Abs(curv.FirstParameter()) >= 1E6 ) || 
+       if ( (Abs(curv.FirstParameter()) >= 1E6 ) ||
             (Abs(curv.LastParameter()) >= 1E6 )) {
          return "Line" ;
        } else
@@ -293,14 +296,14 @@ const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
 {
   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
   GEOM::GEOM_Gen_var  Geom = GEOM::GEOM_Gen::_narrow(comp);
+
   GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
   TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
 
   if( shape.IsNull() ) {
     return "None" ;
   }
-      
+
   switch (shape.ShapeType() )
     {
     case TopAbs_COMPOUND: