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