]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI.cxx
Salome HOME
Porting to Qt4.
[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
32 #include "SUIT_Desktop.h"
33 #include "SUIT_ViewWindow.h"
34 #include "OCCViewer_ViewModel.h"
35 #include "OCCViewer_ViewManager.h"
36 #include "SalomeApp_Study.h"
37 #include "SalomeApp_Application.h"
38
39 #include <TopoDS_Shape.hxx>
40
41 #include "EntityGUI_SketcherDlg.h" // Sketcher
42 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
43
44 #include "utilities.h"
45
46 using namespace boost;
47 using namespace std;
48
49 //=======================================================================
50 // function : EntityGUI()
51 // purpose  : Constructor
52 //=======================================================================
53 EntityGUI::EntityGUI( GeometryGUI* parent ) :  GEOMGUI( parent )
54 {
55   mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
56   mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
57 }
58
59 //=======================================================================
60 // function : ~EntityGUI()
61 // purpose  : Destructor
62 //=======================================================================
63 EntityGUI::~EntityGUI()
64 {
65 }
66
67
68 //=======================================================================
69 // function : OnGUIEvent()
70 // purpose  : 
71 //=======================================================================
72 bool EntityGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
73 {
74   SalomeApp_Application* app = getGeometryGUI()->getApp();
75   if ( !app ) return false;
76
77   getGeometryGUI()->EmitSignalDeactivateDialog();
78   QDialog* aDlg = NULL;
79
80   switch (theCommandID)
81   {
82     case 404: // SKETCHER
83       getGeometryGUI()->ActiveWorkingPlane();
84       aDlg = new EntityGUI_SketcherDlg(getGeometryGUI(), parent, "");
85       break;
86     case 407: // EXPLODE : use ic
87       aDlg = new EntityGUI_SubShapeDlg(getGeometryGUI(), parent, "");
88       break;
89     default:
90       app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
91       break;
92   }
93   if ( aDlg )
94     aDlg->show();
95
96   return true;
97 }
98
99
100 //=====================================================================================
101 // function : DisplaySimulationShape() 
102 // purpose  : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
103 //=====================================================================================
104 void EntityGUI::DisplaySimulationShape(const TopoDS_Shape& S1, const TopoDS_Shape& S2) 
105 {
106   SalomeApp_Application* app = getGeometryGUI()->getApp();
107   if ( !app ) return;
108
109   SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
110   if (aVM->getType() != OCCViewer_Viewer::Type())
111     return;
112
113   OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aVM)->getOCCViewer();
114   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
115   try {
116     if (!S1.IsNull()) {
117       /* erase any previous */
118       ic->Erase(mySimulationShape1, Standard_True, Standard_False);
119       ic->ClearPrs(mySimulationShape1);
120
121       mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
122       mySimulationShape1->Set(S1);
123       mySimulationShape1->SetColor(Quantity_NOC_RED);
124
125       ic->Deactivate(mySimulationShape1);
126       ic->Display(mySimulationShape1, Standard_False);
127       mySimulationShape1->UnsetColor();
128     }
129     if (!S2.IsNull()) {
130       ic->Erase(mySimulationShape2, Standard_True, Standard_False);
131       ic->ClearPrs(mySimulationShape2);
132
133       mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
134       mySimulationShape2->Set(S2);
135       mySimulationShape2->SetColor(Quantity_NOC_VIOLET);
136
137       ic->Deactivate(mySimulationShape2);
138       ic->Display(mySimulationShape2, Standard_False);
139       mySimulationShape2->UnsetColor();
140     }
141     ic->UpdateCurrentViewer();
142   }
143   catch(Standard_Failure) {
144     MESSAGE("Exception catched in EntityGUI::DisplaySimulationShape ");
145   } 
146   return;
147 }
148
149 //==================================================================================
150 // function : EraseSimulationShape()
151 // purpose  : Clears the display of 'mySimulationShape' a pure graphical shape
152 //==================================================================================
153 void EntityGUI::EraseSimulationShape()
154 {
155   SalomeApp_Application* app = getGeometryGUI()->getApp();
156   if ( !app ) return;
157
158   // get all view windows at the desktop
159   QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
160   //get all view windows, which belong to the active study
161   QList<SUIT_ViewWindow*> aWndLstAS;
162   SUIT_ViewWindow* vw;
163
164   QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
165   while ( itWL.hasNext() && (vw = itWL.next()) )
166     if ( vw->getViewManager()->study() == app->activeStudy() )
167       aWndLstAS.append( vw );
168
169   QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
170   while ( itWLAS.hasNext() && (vw = itWLAS.next()) ) {
171     if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
172       OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(vw->getViewManager()))->getOCCViewer();
173       Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
174       ic->Erase(mySimulationShape1, Standard_True, Standard_False);
175       ic->ClearPrs(mySimulationShape1);
176       ic->Erase(mySimulationShape2, Standard_True, Standard_False);
177       ic->ClearPrs(mySimulationShape2);
178       ic->UpdateCurrentViewer();
179     } 
180   }
181 }
182
183 //=====================================================================================
184 // function : SObjectExist()
185 // purpose  :
186 //=====================================================================================
187 bool EntityGUI::SObjectExist(const _PTR(SObject)& theFatherObject, const char* IOR)
188 {
189   SalomeApp_Application* app = getGeometryGUI()->getApp();
190   if ( !app ) return false;
191   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
192   if ( !appStudy ) return false;
193
194   _PTR(Study) aStudy = appStudy->studyDS();
195   _PTR(ChildIterator) it ( aStudy->NewChildIterator(theFatherObject) );
196   _PTR(SObject) RefSO;
197   _PTR(GenericAttribute) anAttr;
198   for(; it->More();it->Next()) {
199     _PTR(SObject) SO ( it->Value() );
200     if(SO->FindAttribute(anAttr, "AttributeIOR")) {
201       _PTR(AttributeIOR) anIOR ( anAttr  );
202       if(strcmp( anIOR->Value().c_str(), IOR ) == 0)
203         return true;
204     }
205     if(SO->ReferencedObject(RefSO)) {
206       if(RefSO->FindAttribute(anAttr, "AttributeIOR")) {
207         _PTR(AttributeIOR) anIOR ( anAttr );
208         if(strcmp(anIOR->Value().c_str(), IOR) == 0)
209           return true;
210       }
211     }
212   }
213   return false;
214 }
215
216
217 //=====================================================================================
218 // EXPORTED METHODS
219 //=====================================================================================
220 extern "C"
221 {
222 GEOM_ENTITYGUI_EXPORT
223   GEOMGUI* GetLibGUI( GeometryGUI* parent )
224   {
225     return new EntityGUI( parent );
226   }
227 }