Salome HOME
5fd229aaf6d214bb6852c7eba715f5019d20c927
[modules/geom.git] / src / EntityGUI / EntityGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : EntityGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "EntityGUI.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_AssemblyBuilder.h"
32
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_ViewWindow.h"
36 #include "OCCViewer_ViewModel.h"
37 #include "OCCViewer_ViewManager.h"
38 #include "SalomeApp_Study.h"
39 #include "SalomeApp_Tools.h"
40 #include "SalomeApp_Application.h"
41
42 #include <TopoDS_Compound.hxx>
43 #include <BRep_Builder.hxx>
44 #include <TopExp_Explorer.hxx>
45
46 #include "EntityGUI_SketcherDlg.h" // Sketcher
47 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
48
49 #include "utilities.h"
50
51 using namespace boost;
52 using namespace std;
53
54 //=======================================================================
55 // function : EntityGUI()
56 // purpose  : Constructor
57 //=======================================================================
58 EntityGUI::EntityGUI( GeometryGUI* parent ) :  GEOMGUI( parent )
59 {
60   mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
61   mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
62 }
63
64 //=======================================================================
65 // function : ~EntityGUI()
66 // purpose  : Destructor
67 //=======================================================================
68 EntityGUI::~EntityGUI()
69 {
70 }
71
72
73 //=======================================================================
74 // function : OnGUIEvent()
75 // purpose  : 
76 //=======================================================================
77 bool EntityGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
78 {
79   SalomeApp_Application* app = getGeometryGUI()->getApp();
80   if ( !app ) return false;
81
82   getGeometryGUI()->EmitSignalDeactivateDialog();
83   QDialog* aDlg = NULL;
84
85   switch (theCommandID)
86   {
87     case 404: // SKETCHER
88       getGeometryGUI()->ActiveWorkingPlane();
89       aDlg = new EntityGUI_SketcherDlg(getGeometryGUI(), parent, "");
90       break;
91     case 407: // EXPLODE : use ic
92       aDlg = new EntityGUI_SubShapeDlg(getGeometryGUI(), parent, "");
93       break;
94     default:
95       app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
96       break;
97   }
98   if ( aDlg )
99     aDlg->show();
100
101   return true;
102 }
103
104
105 //=====================================================================================
106 // function : DisplaySimulationShape() 
107 // purpose  : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
108 //=====================================================================================
109 void EntityGUI::DisplaySimulationShape(const TopoDS_Shape& S1, const TopoDS_Shape& S2) 
110 {
111   SalomeApp_Application* app = getGeometryGUI()->getApp();
112   if ( !app ) return;
113
114   SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
115   if (aVM->getType() != OCCViewer_Viewer::Type())
116     return;
117
118   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aVM)->getOCCViewer();
119   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
120   try {
121     if (!S1.IsNull()) {
122       /* erase any previous */
123       ic->Erase(mySimulationShape1, Standard_True, Standard_False);
124       ic->ClearPrs(mySimulationShape1);
125
126       mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
127       mySimulationShape1->Set(S1);
128       mySimulationShape1->SetColor(Quantity_NOC_RED);
129
130       ic->Deactivate(mySimulationShape1);
131       ic->Display(mySimulationShape1, Standard_False);
132       mySimulationShape1->UnsetColor();
133     }
134     if (!S2.IsNull()) {
135       ic->Erase(mySimulationShape2, Standard_True, Standard_False);
136       ic->ClearPrs(mySimulationShape2);
137
138       mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
139       mySimulationShape2->Set(S2);
140       mySimulationShape2->SetColor(Quantity_NOC_VIOLET);
141
142       ic->Deactivate(mySimulationShape2);
143       ic->Display(mySimulationShape2, Standard_False);
144       mySimulationShape2->UnsetColor();
145     }
146     ic->UpdateCurrentViewer();
147   }
148   catch(Standard_Failure) {
149     MESSAGE("Exception catched in EntityGUI::DisplaySimulationShape ");
150   } 
151   return;
152 }
153
154 //==================================================================================
155 // function : EraseSimulationShape()
156 // purpose  : Clears the display of 'mySimulationShape' a pure graphical shape
157 //==================================================================================
158 void EntityGUI::EraseSimulationShape()
159 {
160   SalomeApp_Application* app = getGeometryGUI()->getApp();
161   if ( !app ) return;
162
163   // get all view windows at the desktop
164   QPtrList<SUIT_ViewWindow> aWndLst = app->desktop()->windows();
165   //get all view windows, which belong to the active study
166   QPtrList<SUIT_ViewWindow> aWndLstAS;
167   SUIT_ViewWindow* vw;
168   for ( vw = aWndLst.first(); vw; vw = aWndLst.next() )
169     if ( vw->getViewManager()->study() == app->activeStudy() )
170       aWndLstAS.append( vw );
171
172   for ( vw = aWndLstAS.first(); vw; vw = aWndLstAS.next() ) {
173     if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
174       OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(vw->getViewManager()))->getOCCViewer();
175       Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
176       ic->Erase(mySimulationShape1, Standard_True, Standard_False);
177       ic->ClearPrs(mySimulationShape1);
178       ic->Erase(mySimulationShape2, Standard_True, Standard_False);
179       ic->ClearPrs(mySimulationShape2);
180       ic->UpdateCurrentViewer();
181     } 
182   }
183 }
184
185 //=====================================================================================
186 // function : SObjectExist()
187 // purpose  :
188 //=====================================================================================
189 bool EntityGUI::SObjectExist(const _PTR(SObject)& theFatherObject, const char* IOR)
190 {
191   SalomeApp_Application* app = getGeometryGUI()->getApp();
192   if ( !app ) return false;
193   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
194   if ( !appStudy ) return false;
195
196   _PTR(Study) aStudy = appStudy->studyDS();
197   _PTR(ChildIterator) it ( aStudy->NewChildIterator(theFatherObject) );
198   _PTR(SObject) RefSO;
199   _PTR(GenericAttribute) anAttr;
200   for(; it->More();it->Next()) {
201     _PTR(SObject) SO ( it->Value() );
202     if(SO->FindAttribute(anAttr, "AttributeIOR")) {
203       _PTR(AttributeIOR) anIOR ( anAttr  );
204       if(strcmp( anIOR->Value().c_str(), IOR ) == 0)
205         return true;
206     }
207     if(SO->ReferencedObject(RefSO)) {
208       if(RefSO->FindAttribute(anAttr, "AttributeIOR")) {
209         _PTR(AttributeIOR) anIOR ( anAttr );
210         if(strcmp(anIOR->Value().c_str(), IOR) == 0)
211           return true;
212       }
213     }
214   }
215   return false;
216 }
217
218
219 //=====================================================================================
220 // EXPORTED METHODS
221 //=====================================================================================
222 extern "C"
223 {
224 #ifdef WNT
225         __declspec( dllexport )
226 #endif
227   GEOMGUI* GetLibGUI( GeometryGUI* parent )
228   {
229     return new EntityGUI( parent );
230   }
231 }