Back to index

salome-geom  6.5.0
GeometryGUI_Swig.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : GeometryGUI_Swig.cxx
00025 // Author : Nicolas REJNERI, Paul RASCLE
00026 //
00027 #include "GeometryGUI_Swig.hxx"
00028 
00029 #include "GeometryGUI.h"
00030 
00031 #include "SUIT_Desktop.h"
00032 #include "SUIT_Session.h"
00033 #include "SalomeApp_Application.h"
00034 #include "SalomeApp_Study.h"
00035 
00036 #include "OB_Browser.h"
00037 
00038 #include "OCCViewer_ViewWindow.h"
00039 #include "OCCViewer_ViewManager.h"
00040 #include "SOCC_ViewModel.h"
00041 #include <SOCC_Prs.h>
00042 
00043 #include "SVTK_ViewModel.h"
00044 #include "SVTK_ViewWindow.h"
00045 #include "SVTK_View.h"
00046 #include "SVTK_Renderer.h"
00047 #include <SVTK_Prs.h>
00048 
00049 #include "GEOM_Actor.h"
00050 #include "GEOM_Client.hxx"
00051 #include "GEOM_AISShape.hxx"
00052 #include "GEOM_InteractiveObject.hxx"
00053 #include "GEOM_Displayer.h"
00054 
00055 #include "SALOME_Event.h"
00056 
00057 // OCCT Includes
00058 #include <TopAbs.hxx>
00059 #include <TopoDS_Shape.hxx>
00060 #include <AIS_ListOfInteractive.hxx>
00061 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00062 #include <AIS_Drawer.hxx>
00063 #include <BRepTools.hxx>
00064 
00065 // IDL Headers
00066 #include <SALOMEconfig.h>
00067 #include CORBA_SERVER_HEADER(GEOM_Gen)
00068 
00069 #include <vtkRenderer.h>
00070 
00071 static SHAPE_READER(ShapeReader);
00072 
00073 inline OCCViewer_Viewer* GetOCCViewer(SUIT_Application* theApp){
00074   SUIT_ViewWindow* window = theApp->desktop()->activeWindow();
00075   if(window && window->getViewManager()->getType() == OCCViewer_Viewer::Type()){
00076     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
00077     if ( vw ) {
00078       OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() );
00079       if ( vm )
00080         return vm->getOCCViewer();
00081     }
00082   }
00083 
00084   return 0;
00085 }
00086 
00087 inline SVTK_ViewWindow* GetSVTKViewWindow(SUIT_Application* theApp){
00088   SUIT_ViewWindow* window = theApp->desktop()->activeWindow();
00089   if(window && window->getViewManager()->getType() == SVTK_Viewer::Type())
00090     return dynamic_cast<SVTK_ViewWindow*>( window );
00091 
00092   return 0;
00093 }
00094 
00095 GEOM_Swig::GEOM_Swig()
00096 {
00097   // MESSAGE("Constructeur");
00098 }
00099 
00100 GEOM_Swig::~GEOM_Swig()
00101 {
00102   // MESSAGE("Destructeur");
00103 }
00104 
00105 void GEOM_Swig::createAndDisplayGO (const char* Entry, bool isUpdated)
00106 {
00107   class TEvent: public SALOME_Event
00108   {
00109     std::string myEntry;
00110     bool        myUpdateViewer;
00111   public:
00112     TEvent(const char* theEntry, bool toUpdateViewer):
00113       myEntry(theEntry),
00114       myUpdateViewer(toUpdateViewer)
00115     {}
00116     virtual void Execute()
00117     {
00118       SUIT_Application* app = SUIT_Session::session()->activeApplication();
00119       if (!app) return;
00120 
00121       SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00122       if (!ActiveStudy) return;
00123 
00124       _PTR(Study) aStudy(ActiveStudy->studyDS());
00125       _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
00126 
00127       GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
00128       if (CORBA::is_nil(Geom)) {
00129         GeometryGUI::InitGeomGen();
00130         Geom = GeometryGUI::GetGeomGen();
00131       }
00132       if (CORBA::is_nil(Geom))
00133         return;
00134 
00135       std::string aFatherIOR;
00136       _PTR(SComponent) father = aStudy->FindComponent("GEOM");
00137       if (!father)
00138         return;
00139       if (!father->ComponentIOR(aFatherIOR)) {
00140         CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(Geom);
00141         aStudyBuilder->LoadWith(father, objStr.in());
00142         father->ComponentIOR(aFatherIOR);
00143       }
00144 
00145       _PTR(SObject) obj = aStudy->FindObjectID(myEntry);
00146       if (!obj)
00147         return;
00148 
00149       // Create new actor
00150       _PTR(GenericAttribute) anAttr;
00151       if (!obj->FindAttribute(anAttr, "AttributeIOR"))
00152         return;
00153       _PTR(AttributeIOR) anIOR(anAttr);
00154       std::string anIORValue = anIOR->Value();
00155 
00156       GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue.c_str());
00157       TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
00158       if (!Shape.IsNull()) {
00159         if (obj->FindAttribute(anAttr, "AttributeName")) {
00160           _PTR(AttributeName) aName (anAttr);
00161           std::string aNameValue = aName->Value();
00162           // open transaction
00163           /*SUIT_Operation* op = new SalomeApp_ImportOperation (app);
00164           op->start();
00165 
00166           _PTR(SObject) newObj1 = aStudyBuilder->NewObject(father);
00167           aStudyBuilder->Addreference(newObj1, obj);
00168           // commit transaction
00169           op->commit();*/
00170           Handle(GEOM_InteractiveObject) anIO =
00171             new GEOM_InteractiveObject (const_cast<char*>(anIORValue.c_str()),
00172                                         const_cast<char*>(aFatherIOR.c_str()),
00173                                         "GEOM",
00174                                         const_cast<char*>( obj->GetID().c_str()));
00175 
00176           GEOM_Displayer(ActiveStudy).Display(anIO, myUpdateViewer);
00177           /*if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(app)) {
00178             SVTK_View* aView = aViewWindow->getView();
00179             int aMode = aView->GetDisplayMode();
00180 
00181             vtkActorCollection* theActors =
00182               GEOM_AssemblyBuilder::BuildActors(Shape,0,aMode,true);
00183             theActors->InitTraversal();
00184             while (vtkActor* anActor = theActors->GetNextActor()) {
00185               GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
00186               GActor->setName(const_cast<char*>(aNameValue.c_str()));
00187               GActor->setIO(anIO);
00188               aView->Display(GActor);
00189             }
00190             aView->Repaint();
00191           } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app)) {
00192             Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
00193             Handle(GEOM_AISShape) aSh =
00194               new GEOM_AISShape (Shape,const_cast<char*>(aNameValue.c_str()));
00195             aSh->setName(const_cast<char*>(aNameValue.c_str()));
00196             aSh->setIO(anIO);
00197             ic->Display(aSh);
00198             ic->AddOrRemoveCurrentObject(aSh,true);
00199             }*/
00200           // update object browser
00201           SalomeApp_Application* app = NULL; //dynamic_cast<SalomeApp_Application*>(app);
00202           if (app) {
00203             CAM_Module* module = app->module("Geometry");
00204             SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>(module);
00205             if (appMod)
00206               appMod->updateObjBrowser(true);
00207           }
00208         }
00209       }
00210     }
00211   };
00212 
00213   // MESSAGE("createAndDisplayGO");
00214   ProcessVoidEvent(new TEvent (Entry, isUpdated));
00215 
00216   class TEventUpdateBrowser: public SALOME_Event
00217     {
00218       public:
00219         TEventUpdateBrowser() {}
00220         virtual void Execute() {
00221           SalomeApp_Application* app =
00222             dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
00223           if (app) {
00224             CAM_Module* module = app->module("Geometry");
00225             SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>(module);
00226             if (appMod) appMod->updateObjBrowser(true);
00227           }
00228         }
00229     };
00230 
00231   if (isUpdated)
00232     ProcessVoidEvent(new TEventUpdateBrowser ());
00233 }
00234 
00235 void GEOM_Swig::createAndDisplayFitAllGO (const char* Entry)
00236 {
00237   class TEventFitAll: public SALOME_Event
00238   {
00239     public:
00240       TEventFitAll() {}
00241       virtual void Execute() {
00242         SUIT_Application* app = SUIT_Session::session()->activeApplication();
00243         if (!app) return;
00244         
00245         if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(app))
00246           {
00247             SVTK_View* aView = aViewWindow->getView();
00248             aView->GetRenderer()->OnFitAll();
00249           }
00250         else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app))
00251           {  
00252             Handle(V3d_Viewer) aViewer3d = occViewer->getViewer3d();
00253             aViewer3d->InitActiveViews();
00254             
00255             if (aViewer3d->MoreActiveViews())
00256               aViewer3d->ActiveView()->FitAll();
00257           }
00258       }
00259   };
00260 
00261   createAndDisplayGO(Entry);
00262   ProcessVoidEvent(new TEventFitAll());
00263 }
00264 
00265 void GEOM_Swig::UpdateViewer()
00266 {
00267   class TEventUpdateViewer: public SALOME_Event
00268   {
00269     public:
00270       TEventUpdateViewer() {}
00271       virtual void Execute() {
00272         SUIT_Application* app = SUIT_Session::session()->activeApplication();
00273         if (!app) return;
00274         SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00275         if (!ActiveStudy) return;
00276         
00277         GEOM_Displayer(ActiveStudy).UpdateViewer();
00278       }
00279   };
00280   
00281   ProcessVoidEvent(new TEventUpdateViewer());
00282 }
00283 
00284 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
00285 {
00286   GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
00287   if (CORBA::is_nil(aGeomGen))
00288     return -1;
00289 
00290   GEOM::GEOM_Object_var aMainShape = aGeomGen->GetIORFromString(IOR);
00291   GEOM::GEOM_Object_var aSubShape  = aGeomGen->GetIORFromString(SubIOR);
00292   if (CORBA::is_nil(aMainShape) || CORBA::is_nil(aSubShape))
00293     return -1;
00294 
00295   GEOM::GEOM_IShapesOperations_var anIShapesOperations =
00296     aGeomGen->GetIShapesOperations(aMainShape->GetStudyID());
00297   if (CORBA::is_nil(anIShapesOperations))
00298     return -1;
00299 
00300   return anIShapesOperations->GetTopologyIndex(aMainShape, aSubShape);
00301 }
00302 
00303 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
00304 {
00305   TCollection_AsciiString aTypeName ("Shape of unknown type");
00306 
00307   GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
00308   if (!CORBA::is_nil(aGeomGen))
00309   {
00310     GEOM::GEOM_Object_var aShape = aGeomGen->GetIORFromString(IOR);
00311     if (!CORBA::is_nil(aShape))
00312     {
00313       GEOM::GEOM_IShapesOperations_var anIShapesOperations =
00314         aGeomGen->GetIShapesOperations(aShape->GetStudyID());
00315       if (!CORBA::is_nil(anIShapesOperations))
00316       {
00317         aTypeName = anIShapesOperations->GetShapeTypeString(aShape);
00318       }
00319     }
00320   }
00321 
00322   return CORBA::string_dup(aTypeName.ToCString());
00323 }
00324 
00325 
00326 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
00327 {
00328   GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
00329   if ( CORBA::is_nil( Geom ) )
00330     return "None";
00331 
00332   GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
00333   TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
00334 
00335   if( shape.IsNull() ) {
00336     return "None" ;
00337   }
00338 
00339   switch (shape.ShapeType() )
00340     {
00341     case TopAbs_COMPOUND:
00342       { return "ICON_OBJBROWSER_COMPOUND" ;}
00343     case  TopAbs_COMPSOLID:
00344       { return "ICON_OBJBROWSER_COMPSOLID" ;}
00345     case TopAbs_SOLID:
00346       { return "ICON_OBJBROWSER_SOLID" ;}
00347     case TopAbs_SHELL:
00348       { return "ICON_OBJBROWSER_SHELL" ;}
00349     case TopAbs_FACE:
00350       { return "ICON_OBJBROWSER_FACE" ;}
00351     case TopAbs_WIRE:
00352       { return "ICON_OBJBROWSER_WIRE" ;}
00353     case TopAbs_EDGE:
00354       { return "ICON_OBJBROWSER_EDGE" ;}
00355     case TopAbs_VERTEX:
00356       { return "ICON_OBJBROWSER_VERTEX" ;}
00357     }
00358 
00359   return "None";
00360 }
00361 
00362 void GEOM_Swig::setDisplayMode(const char* theEntry, int theMode, bool isUpdated)
00363 {
00364   class TEvent: public SALOME_Event {
00365     std::string myEntry;
00366     int myMode;
00367     bool myUpdateViewer;
00368   public:
00369     TEvent(const char* theEntryArg, int theModeArg, bool theUpdated):
00370       myEntry(theEntryArg), myMode(theModeArg), myUpdateViewer(theUpdated)
00371     {}
00372     virtual void Execute() {
00373       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
00374       if (!anApp) return;
00375 
00376       Handle(SALOME_InteractiveObject) anIO =
00377         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00378 
00379       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
00380         SVTK_View* aView = aViewWindow->getView();
00381         aView->SetDisplayMode(anIO, myMode);
00382         if (myUpdateViewer)
00383           aView->Repaint();
00384       }
00385       else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
00386         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
00387         if (soccViewer)
00388           soccViewer->switchRepresentation(anIO, myMode, myUpdateViewer);
00389       }
00390     }
00391   };
00392 
00393   ProcessVoidEvent(new TEvent (theEntry, theMode, isUpdated));
00394 }
00395 
00396 void GEOM_Swig::setVectorsMode(const char* theEntry, bool isOn, bool isUpdated)
00397 {
00398   class TEvent: public SALOME_Event {
00399     std::string myEntry;
00400     bool myOn;
00401     bool myUpdateViewer;
00402   public:
00403     TEvent(const char* theEntryArg, bool theOn, bool theUpdated):
00404       myEntry(theEntryArg), myOn(theOn), myUpdateViewer(theUpdated)
00405     {}
00406     virtual void Execute() {
00407       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
00408       if (!anApp) return;
00409 
00410       Handle(SALOME_InteractiveObject) anIO =
00411         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00412 
00413       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
00414         SVTK_View* aView = aViewWindow->getView();
00415         SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(aViewWindow->getViewManager()->getViewModel());
00416         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( myEntry.c_str()  ) );
00417         vtkActorCollection* anActors = vtkPrs->GetObjects();
00418         anActors->InitTraversal();
00419         while (vtkActor* anAct = anActors->GetNextActor()) {
00420           GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
00421           aGeomActor->SetVectorMode(!aGeomActor->GetVectorMode());
00422         }
00423         if (myUpdateViewer)
00424           aView->Repaint();
00425       }
00426       else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
00427         Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
00428         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
00429         if (soccViewer) {
00430           SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( myEntry.c_str() ) );
00431           if ( occPrs && !occPrs->IsNull() ) {
00432             AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
00433             AIS_ListIteratorOfListOfInteractive interIter( shapes );
00434             for ( ; interIter.More(); interIter.Next() ) {
00435               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
00436               aSh->SetDisplayVectors(myOn);
00437               ic->RecomputePrsOnly(interIter.Value());
00438             }
00439           }
00440         }
00441       }
00442     }
00443   };
00444 
00445   ProcessVoidEvent(new TEvent (theEntry, isOn, isUpdated));
00446 }
00447 
00448 void GEOM_Swig::setColor(const char* theEntry, int red, int green, int blue, bool isUpdated)
00449 {
00450   class TEvent: public SALOME_Event {
00451     std::string myEntry;
00452     int myRed;
00453     int myGreen;
00454     int myBlue;
00455     bool myUpdateViewer;
00456   public:
00457     TEvent(const char* theEntryArg, int theR, int theG, int theB, bool theUpdated):
00458       myEntry(theEntryArg), myRed(theR), myGreen(theG), myBlue(theB), myUpdateViewer(theUpdated)
00459     {}
00460     virtual void Execute() {
00461       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
00462       if (!anApp) return;
00463 
00464       Handle(SALOME_InteractiveObject) anIO =
00465         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00466 
00467       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)){
00468         SVTK_View* aView = aViewWindow->getView();
00469         QColor aColor (myRed, myGreen, myBlue);
00470         aView->SetColor(anIO, aColor);
00471         if (myUpdateViewer)
00472           aView->Repaint();
00473       } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
00474         Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
00475         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
00476         if (soccViewer)
00477           {
00478             SALOME_Prs*   prs=      soccViewer->CreatePrs( myEntry.c_str() );
00479             const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );
00480             if ( !anOCCPrs || anOCCPrs->IsNull() )
00481               return;
00482 
00483             // get objects to be displayed
00484             AIS_ListOfInteractive anAISObjects;
00485             anOCCPrs->GetObjects( anAISObjects );
00486             AIS_ListIteratorOfListOfInteractive ite( anAISObjects );
00487             Quantity_Color CSFColor = Quantity_Color(myRed/255., myGreen/255., myBlue/255., Quantity_TOC_RGB);
00488             for ( ; ite.More(); ite.Next() )
00489               {
00490                 if(!ic->IsDisplayed(ite.Value()))continue;  //only displayed ais 
00491                 ite.Value()->SetColor(CSFColor);
00492                 if (ite.Value()->IsKind(STANDARD_TYPE(GEOM_AISShape))) Handle(GEOM_AISShape)::DownCast(ite.Value())->SetShadingColor(CSFColor);
00493                 ite.Value()->Redisplay(Standard_True); // as in OnColor
00494               }
00495             if (myUpdateViewer) occViewer->update();
00496           }
00497       }
00498     }
00499   };
00500   ProcessVoidEvent(new TEvent(theEntry, red, green, blue, isUpdated));
00501 }
00502 
00503 void GEOM_Swig::setTransparency(const char* theEntry, float transp, bool isUpdated)
00504 {
00505   class TEvent: public SALOME_Event {
00506     std::string myEntry;
00507     float myParam;
00508     bool myUpdateViewer;
00509   public:
00510     TEvent(const char* theEntryArg, float theParam, bool theUpdated):
00511       myEntry(theEntryArg), myParam(theParam), myUpdateViewer(theUpdated)
00512     {}
00513     virtual void Execute() {
00514       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
00515       if (!anApp) return;
00516 
00517       Handle(SALOME_InteractiveObject) anIO =
00518         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00519 
00520       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
00521         SVTK_View* aView = aViewWindow->getView();
00522         aView->SetTransparency(anIO, myParam);
00523         if (myUpdateViewer)
00524           aView->Repaint();
00525       } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
00526         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
00527         if (soccViewer)
00528           soccViewer->setTransparency(anIO, myParam, myUpdateViewer);
00529       }
00530     }
00531   };
00532 
00533   ProcessVoidEvent(new TEvent (theEntry, transp, isUpdated));
00534 }
00535 
00536 
00537 class TInitGeomGenEvent: public SALOME_Event {
00538 public:
00539   typedef bool TResult;
00540   TResult myResult;
00541   TInitGeomGenEvent() : myResult(false) {}
00542   virtual void Execute() {
00543     myResult = GeometryGUI::InitGeomGen();
00544   }
00545 };
00546 bool GEOM_Swig::initGeomGen()
00547 {
00548   return ProcessEvent(new TInitGeomGenEvent());
00549 }
00550 
00551 
00552 
00553 void GEOM_Swig::eraseGO (const char* Entry, bool allWindows)
00554 {
00555   class TEvent: public SALOME_Event
00556   {
00557     std::string myEntry;
00558     bool myFromAllWindows;
00559   public:
00560     TEvent(const char* theEntry, bool fromAllWindows):
00561       myEntry(theEntry), myFromAllWindows(fromAllWindows)
00562     {}
00563     virtual void Execute()
00564     {
00565       SUIT_Application* app = SUIT_Session::session()->activeApplication();
00566       if (!app) return;
00567       SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00568       if (!ActiveStudy) return;
00569 
00570       Handle (SALOME_InteractiveObject) aIO = new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00571 
00572       GEOM_Displayer(ActiveStudy).Erase(aIO, true);
00573       /*      if (myFromAllWindows) {
00574         QPtrList<SUIT_ViewWindow> aWindows = app->desktop()->windows();
00575         SUIT_ViewWindow* aWin = 0;
00576         for (aWin = aWindows.first(); aWin; aWin = aWindows.next()) {
00577           EraseObject(aWin, aIO);
00578         }
00579       } else {
00580         SUIT_ViewWindow* aWin = app->desktop()->activeWindow();
00581         if (aWin)
00582           EraseObject(aWin, aIO);
00583           }*/
00584     }
00585 
00586     /*  private:
00587     void EraseObject(SUIT_ViewWindow* theWin, Handle (SALOME_InteractiveObject) theIO)
00588     {
00589       if (theWin->getViewManager()->getType() == OCCViewer_Viewer::Type()){
00590         OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( theWin );
00591         if ( vw ) {
00592           OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() );
00593           if ( vm ) {
00594             SOCC_Viewer* aViewer = dynamic_cast<SOCC_Viewer*>(vm->getOCCViewer());
00595             if (aViewer) {
00596               SALOME_Prs* aPrs = aViewer->CreatePrs(myEntry.c_str());
00597               if (aPrs) {
00598                 SALOME_OCCPrs* aOccPrs =  dynamic_cast<SALOME_OCCPrs*>(aPrs);
00599                 if (aOccPrs) {
00600                   aViewer->Erase(aOccPrs);
00601                   aViewer->Repaint();
00602                 }
00603               }
00604             }
00605           }
00606         }
00607       } else if (theWin->getViewManager()->getType() == SVTK_Viewer::Type()){
00608         SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( theWin );
00609         if (aViewWindow) {
00610           aViewWindow->Erase(theIO);
00611         }
00612       }
00613       }*/
00614 
00615   };
00616   ProcessVoidEvent(new TEvent(Entry, allWindows));
00617 }
00618 
00619 
00620 
00621 void GEOM_Swig::setDeflection(const char* theEntry, float theDeflect)
00622 {
00623   class TEvent: public SALOME_Event {
00624     std::string myEntry;
00625     float myParam;
00626   public:
00627     TEvent(const char* theEntryArg, float theParam):
00628       myEntry(theEntryArg), myParam(theParam)
00629     {}
00630     virtual void Execute() {
00631       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
00632       if (!anApp) return;
00633 
00634       Handle(SALOME_InteractiveObject) anIO =
00635         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
00636 
00637       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
00638         vtkActorCollection* aActors = aViewWindow->getRenderer()->GetActors();
00639         aActors->InitTraversal();
00640         while (vtkActor* aAct = aActors->GetNextActor()) {
00641           if (GEOM_Actor* aGeomActor = dynamic_cast<GEOM_Actor*>(aAct)) {
00642             if (aGeomActor->hasIO()) {
00643               Handle(SALOME_InteractiveObject) aNextIO = aGeomActor->getIO();
00644               if (aNextIO->isSame(anIO)) {
00645                 aGeomActor->setDeflection(myParam);
00646                 aViewWindow->Repaint();
00647                 return;
00648               }
00649             }
00650           }
00651         }
00652         //      aView->SetTransparency(anIO, myParam);
00653         //aView->Repaint();
00654       } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
00655         Handle(AIS_InteractiveContext) aContext = occViewer->getAISContext();
00656         AIS_ListOfInteractive aAISList;
00657         aContext->DisplayedObjects(aAISList);
00658         AIS_ListIteratorOfListOfInteractive it(aAISList);
00659         for (; it.More(); it.Next()) {
00660           Handle(SALOME_InteractiveObject) aObj = 
00661             Handle(SALOME_InteractiveObject)::DownCast(it.Value()->GetOwner());
00662           if ((!aObj.IsNull()) && aObj->hasEntry() && aObj->isSame(anIO)) {
00663             Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(it.Value());
00664             if (!aShape.IsNull()) {
00665               TopoDS_Shape aSh = aShape->Shape();
00666               if (!aSh.IsNull())
00667                 BRepTools::Clean(aSh);
00668 
00669               aShape->SetOwnDeviationCoefficient( myParam );
00670               aShape->SetOwnHLRDeviationAngle( 1.57 );
00671               aContext->Redisplay(aShape);
00672               return;
00673             }
00674           }
00675         }
00676       }
00677     }
00678   };
00679 
00680   ProcessVoidEvent(new TEvent (theEntry, theDeflect));
00681 }
00682