Fix crash of BugRevolution.py import

This commit is contained in:
jfa 2005-08-02 06:55:46 +00:00
parent bfd83343c8
commit 1127be211a

View File

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