1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : EntityGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "EntityGUI.h"
29 #include <GeometryGUI.h>
30 #include "GeometryGUI_Operations.h"
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>
39 #include <TopoDS_Shape.hxx>
41 #include "EntityGUI_SketcherDlg.h" // Sketcher
42 #include "EntityGUI_3DSketcherDlg.h" // Sketcher
43 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
45 //=======================================================================
46 // function : EntityGUI()
47 // purpose : Constructor
48 //=======================================================================
49 EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
51 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
52 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
55 //=======================================================================
56 // function : ~EntityGUI()
57 // purpose : Destructor
58 //=======================================================================
59 EntityGUI::~EntityGUI()
64 //=======================================================================
65 // function : OnGUIEvent()
67 //=======================================================================
68 bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
70 SalomeApp_Application* app = getGeometryGUI()->getApp();
71 if ( !app ) return false;
73 getGeometryGUI()->EmitSignalDeactivateDialog();
76 switch ( theCommandID ) {
77 case GEOMOp::Op2dSketcher: // 2D SKETCHER
78 getGeometryGUI()->ActiveWorkingPlane();
79 aDlg = new EntityGUI_SketcherDlg( getGeometryGUI(), parent );
81 case GEOMOp::Op3dSketcher: // 3D SKETCHER
82 aDlg = new EntityGUI_3DSketcherDlg( getGeometryGUI(), parent );
84 case GEOMOp::OpExplode: // EXPLODE
85 aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
88 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
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 )
104 SalomeApp_Application* app = getGeometryGUI()->getApp();
107 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
108 if ( aVM->getType() != OCCViewer_Viewer::Type() )
111 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
112 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
114 if ( !S1.IsNull() ) {
115 /* erase any previous */
116 ic->Erase( mySimulationShape1, Standard_True, Standard_False );
117 ic->ClearPrs( mySimulationShape1 );
119 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
120 mySimulationShape1->Set( S1 );
121 mySimulationShape1->SetColor( Quantity_NOC_RED );
123 ic->Deactivate( mySimulationShape1 );
124 ic->Display( mySimulationShape1, Standard_False );
125 mySimulationShape1->UnsetColor();
127 if ( !S2.IsNull() ) {
128 ic->Erase( mySimulationShape2, Standard_True, Standard_False );
129 ic->ClearPrs( mySimulationShape2 );
131 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
132 mySimulationShape2->Set( S2 );
133 mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
135 ic->Deactivate( mySimulationShape2 );
136 ic->Display( mySimulationShape2, Standard_False );
137 mySimulationShape2->UnsetColor();
139 ic->UpdateCurrentViewer();
141 catch( Standard_Failure ) {
142 MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
146 //==================================================================================
147 // function : EraseSimulationShape()
148 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
149 //==================================================================================
150 void EntityGUI::EraseSimulationShape()
152 SalomeApp_Application* app = getGeometryGUI()->getApp();
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;
161 QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
162 while ( itWL.hasNext() && ( vw = itWL.next() ) )
163 if ( vw->getViewManager()->study() == app->activeStudy() )
164 aWndLstAS.append( vw );
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();
180 //=====================================================================================
181 // function : SObjectExist()
183 //=====================================================================================
184 bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
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;
191 _PTR(Study) aStudy = appStudy->studyDS();
192 _PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
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 )
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 )
214 //=====================================================================================
216 //=====================================================================================
220 __declspec( dllexport )
222 GEOMGUI* GetLibGUI( GeometryGUI* parent )
224 return new EntityGUI( parent );