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