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