Fix crash of BugRevolution.py import: apply the same patch, as on V2_2_0_maintainance

This commit is contained in:
jfa 2005-08-02 09:03:51 +00:00
parent 60efe138c3
commit 40a7e07f71

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
// //
// //
// //
@ -56,6 +56,13 @@
#include <SALOME_Event.hxx> #include <SALOME_Event.hxx>
#include "utilities.h"
#include "SALOMEDSClient.hxx"
#include "SALOMEDS_SObject.hxx"
#include "SALOMEDS_Study.hxx"
// 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>
@ -72,13 +79,8 @@
#include <AIS_ListIteratorOfListOfInteractive.hxx> #include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <V3d_Viewer.hxx> #include <V3d_Viewer.hxx>
#include "utilities.h"
using namespace std; using namespace std;
#include "SALOMEDSClient.hxx"
#include "SALOMEDS_SObject.hxx"
#include "SALOMEDS_Study.hxx"
static GEOM_Client ShapeReader; static GEOM_Client ShapeReader;
@ -88,11 +90,11 @@ inline OCCViewer_Viewer* GetOCCViewer(SUIT_Application* theApp){
OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window ); OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
if ( vw ) { if ( vw ) {
OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() ); OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() );
if ( vm ) if ( vm )
return vm->getOCCViewer(); return vm->getOCCViewer();
} }
} }
return 0; return 0;
} }
@ -100,7 +102,7 @@ inline SVTK_ViewWindow* GetSVTKViewWindow(SUIT_Application* theApp){
SUIT_ViewWindow* window = theApp->desktop()->activeWindow(); SUIT_ViewWindow* window = theApp->desktop()->activeWindow();
if(window && window->getViewManager()->getType() == VTKViewer_Viewer::Type()) if(window && window->getViewManager()->getType() == VTKViewer_Viewer::Type())
return dynamic_cast<SVTK_ViewWindow*>( window ); return dynamic_cast<SVTK_ViewWindow*>( window );
return 0; return 0;
} }
@ -114,106 +116,105 @@ 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
{
SUIT_Application* app = SUIT_Session::session()->activeApplication(); std::string myEntry;
if ( !app ) return; public:
TEvent(const char* theEntry):
SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ); myEntry(theEntry)
if ( !ActiveStudy ) return; {}
virtual void Execute()
_PTR(Study) aStudy(ActiveStudy->studyDS()); {
_PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder(); SUIT_Application* app = SUIT_Session::session()->activeApplication();
if (!app) return;
GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
if ( CORBA::is_nil( Geom ) )
return;
string aFatherIOR; SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
_PTR(SComponent) father = aStudy->FindComponent("GEOM"); if (!ActiveStudy) return;
aStudyBuilder->DefineComponentInstance( father, SalomeApp_Application::orb()->object_to_string(Geom) );
father->ComponentIOR(aFatherIOR);
_PTR(SObject) obj = aStudy->FindObjectID(Entry); _PTR(Study) aStudy(ActiveStudy->studyDS());
_PTR(GenericAttribute) anAttr; _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
// Create new actor GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
if ( !obj->FindAttribute(anAttr, "AttributeIOR")) if (CORBA::is_nil(Geom))
return; return;
_PTR(AttributeIOR) anIOR(anAttr);
string anIORValue = anIOR->Value(); string aFatherIOR;
_PTR(SComponent) father = aStudy->FindComponent("GEOM");
GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue.c_str()); aStudyBuilder->DefineComponentInstance
TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape); (father, SalomeApp_Application::orb()->object_to_string(Geom));
father->ComponentIOR(aFatherIOR);
if ( obj ) {
if (obj->FindAttribute(anAttr, "AttributeName")) { _PTR(SObject) obj = aStudy->FindObjectID(myEntry);
_PTR(AttributeName) aName ( anAttr ); _PTR(GenericAttribute) anAttr;
string aNameValue = aName->Value();
// open transaction // Create new actor
/*jfa for bug IPAL9384 3)c):SUIT_Operation* op = new SalomeApp_ImportOperation( app ); if (!obj->FindAttribute(anAttr, "AttributeIOR"))
op->start(); return;
_PTR(AttributeIOR) anIOR(anAttr);
_PTR(SObject) newObj1 = aStudyBuilder->NewObject(father); string anIORValue = anIOR->Value();
aStudyBuilder->Addreference(newObj1, obj);
// commit transaction GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue.c_str());
op->commit();*/ TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
Handle(GEOM_InteractiveObject) anIO = new GEOM_InteractiveObject(const_cast<char*>(anIORValue.c_str()), if (obj) {
const_cast<char*>(aFatherIOR.c_str()), if (obj->FindAttribute(anAttr, "AttributeName")) {
"GEOM", _PTR(AttributeName) aName (anAttr);
const_cast<char*>( obj->GetID().c_str() )); string aNameValue = aName->Value();
// open transaction
class TEvent: public SALOME_Event{ /*SUIT_Operation* op = new SalomeApp_ImportOperation (app);
SUIT_Application* myApp; op->start();
TopoDS_Shape myShape;
Handle(SALOME_InteractiveObject) myIO; _PTR(SObject) newObj1 = aStudyBuilder->NewObject(father);
const char* myName; aStudyBuilder->Addreference(newObj1, obj);
public: // commit transaction
TEvent(SUIT_Application* theApp, TopoDS_Shape theShape, op->commit();*/
const Handle(SALOME_InteractiveObject)& theIO,
const char* theName): Handle(GEOM_InteractiveObject) anIO =
myApp(theApp), myShape(theShape), new GEOM_InteractiveObject (const_cast<char*>(anIORValue.c_str()),
myIO(theIO), myName(theName) const_cast<char*>(aFatherIOR.c_str()),
{} "GEOM",
virtual void Execute(){ const_cast<char*>( obj->GetID().c_str()));
if(SVTK_ViewWindow* svtkViewWindow = GetSVTKViewWindow(myApp)){
SVTK_RenderWindowInteractor* myRenderInter= svtkViewWindow->getRWInteractor(); if (SVTK_ViewWindow* svtkViewWindow = GetSVTKViewWindow(app)) {
int aMode = myRenderInter->GetDisplayMode(); SVTK_RenderWindowInteractor* aRenderInter= svtkViewWindow->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(); 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.c_str()));
GActor->setIO(myIO); GActor->setIO(anIO);
myRenderInter->Display(GActor); aRenderInter->Display(GActor);
} }
myRenderInter->Update(); aRenderInter->Update();
}else if( OCCViewer_Viewer* occViewer = GetOCCViewer(myApp)){ } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app)) {
Handle(AIS_InteractiveContext) ic = occViewer->getAISContext(); Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
Handle(GEOM_AISShape) aSh = new GEOM_AISShape(myShape,const_cast<char*>(myName)); Handle(GEOM_AISShape) aSh =
aSh->setName(const_cast<char*>(myName)); new GEOM_AISShape (Shape,const_cast<char*>(aNameValue.c_str()));
aSh->setIO(myIO); aSh->setName(const_cast<char*>(aNameValue.c_str()));
aSh->setIO(anIO);
ic->Display(aSh); ic->Display(aSh);
ic->AddOrRemoveCurrentObject(aSh,true); ic->AddOrRemoveCurrentObject(aSh,true);
} }
// update object browser // update object browser
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(myApp); SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(app);
if (app) { if (app) {
CAM_Module* module = app->module( "Geometry" ); CAM_Module* module = app->module("Geometry");
SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module ); SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>(module);
if ( appMod ) if (appMod)
appMod->updateObjBrowser( true ); appMod->updateObjBrowser(true);
} }
} }
}; }
ProcessVoidEvent(new TEvent(app,Shape,anIO,aNameValue.c_str()));
} }
} };
// MESSAGE("createAndDisplayGO");
ProcessVoidEvent(new TEvent (Entry));
} }
@ -222,7 +223,7 @@ int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen(); GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
if ( CORBA::is_nil( Geom ) ) if ( CORBA::is_nil( Geom ) )
return -1; return -1;
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);
@ -230,36 +231,36 @@ 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;
} }
@ -268,7 +269,7 @@ const char* GEOM_Swig::getShapeTypeString(const char* IOR)
GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen(); GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
if ( CORBA::is_nil( Geom ) ) if ( CORBA::is_nil( Geom ) )
return 0; return 0;
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);
@ -287,7 +288,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" ;
@ -306,10 +307,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
@ -337,14 +338,14 @@ const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen(); GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
if ( CORBA::is_nil( Geom ) ) if ( CORBA::is_nil( Geom ) )
return "None"; return "None";
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:
@ -364,7 +365,7 @@ const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
case TopAbs_VERTEX: case TopAbs_VERTEX:
{ return "ICON_OBJBROWSER_VERTEX" ;} { return "ICON_OBJBROWSER_VERTEX" ;}
} }
return "None"; return "None";
} }
@ -372,9 +373,9 @@ void GEOM_Swig::setDisplayMode(const char* theEntry, int theMode)
{ {
SUIT_Application* app = SUIT_Session::session()->activeApplication(); SUIT_Application* app = SUIT_Session::session()->activeApplication();
if ( !app ) return; if ( !app ) return;
Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry, "GEOM", ""); Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry, "GEOM", "");
class TEvent: public SALOME_Event{ class TEvent: public SALOME_Event{
SUIT_Application* myApp; SUIT_Application* myApp;
Handle(SALOME_InteractiveObject) myIO; Handle(SALOME_InteractiveObject) myIO;
@ -453,9 +454,9 @@ void GEOM_Swig::setTransparency(const char* theEntry, float transp)
{ {
SUIT_Application* app = SUIT_Session::session()->activeApplication(); SUIT_Application* app = SUIT_Session::session()->activeApplication();
if ( !app ) return; if ( !app ) return;
Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry, "GEOM", ""); Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry, "GEOM", "");
class TEvent: public SALOME_Event{ class TEvent: public SALOME_Event{
SUIT_Application* myApp; SUIT_Application* myApp;
Handle(SALOME_InteractiveObject) myIO; Handle(SALOME_InteractiveObject) myIO;
@ -476,7 +477,7 @@ void GEOM_Swig::setTransparency(const char* theEntry, float transp)
} }
} }
}; };
ProcessVoidEvent(new TEvent(app,anIO,transp)); ProcessVoidEvent(new TEvent(app,anIO,transp));
} }