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