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$
#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"
@ -36,8 +43,17 @@
#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>
@ -54,19 +70,6 @@
#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,28 +90,38 @@ GEOM_Swig::~GEOM_Swig()
// MESSAGE("Destructeur");
}
void GEOM_Swig::createAndDisplayGO(const char* Entry)
void GEOM_Swig::createAndDisplayGO (const char* Entry)
{
// MESSAGE("createAndDisplayGO");
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");
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 );
aStudyBuilder->DefineComponentInstance(father, Geom);
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::AttributeIOR_var anIOR;
// Create new actor
if ( !obj->FindAttribute(anAttr, "AttributeIOR"))
if (!obj->FindAttribute(anAttr, "AttributeIOR"))
return;
anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
CORBA::String_var anIORValue = anIOR->Value();
@ -116,12 +129,12 @@ void GEOM_Swig::createAndDisplayGO(const char* Entry)
GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue);
TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
if ( !obj->_is_nil() ) {
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 );
QAD_Operation* op = new SALOMEGUI_ImportOperation (ActiveStudy);
op->start();
SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
@ -129,51 +142,41 @@ void GEOM_Swig::createAndDisplayGO(const char* Entry)
// commit transaction
op->finish();
Handle(GEOM_InteractiveObject) anIO = new GEOM_InteractiveObject(const_cast<char*>(anIORValue.in()),
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();
if (VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(ActiveStudy)) {
VTKViewer_RenderWindowInteractor* aRenderInter= aViewFrame->getRWInteractor();
int aMode = aRenderInter->GetDisplayMode();
vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(myShape,0,aMode,true);
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));
}