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

@ -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{ if (VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(ActiveStudy)) {
QAD_Study* myStudy; VTKViewer_RenderWindowInteractor* aRenderInter= aViewFrame->getRWInteractor();
TopoDS_Shape myShape; int aMode = aRenderInter->GetDisplayMode();
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); vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape,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));
} }