1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : EntityGUI.cxx
24 // Author : Damien COQUERET
28 #include "EntityGUI.h"
29 #include "GeometryGUI.h"
30 #include "GEOM_AssemblyBuilder.h"
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"
41 #include <TopoDS_Compound.hxx>
42 #include <BRep_Builder.hxx>
43 #include <TopExp_Explorer.hxx>
45 #include "EntityGUI_SketcherDlg.h" // Sketcher
46 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
48 #include "utilities.h"
50 using namespace boost;
53 //=======================================================================
54 // function : EntityGUI()
55 // purpose : Constructor
56 //=======================================================================
57 EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
59 mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
60 mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
63 //=======================================================================
64 // function : ~EntityGUI()
65 // purpose : Destructor
66 //=======================================================================
67 EntityGUI::~EntityGUI()
72 //=======================================================================
73 // function : OnGUIEvent()
75 //=======================================================================
76 bool EntityGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
78 SalomeApp_Application* app = getGeometryGUI()->getApp();
79 if ( !app ) return false;
81 getGeometryGUI()->EmitSignalDeactivateDialog();
87 getGeometryGUI()->ActiveWorkingPlane();
88 aDlg = new EntityGUI_SketcherDlg(getGeometryGUI(), parent, "");
90 case 407: // EXPLODE : use ic
91 aDlg = new EntityGUI_SubShapeDlg(getGeometryGUI(), parent, "");
94 app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
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)
110 SalomeApp_Application* app = getGeometryGUI()->getApp();
113 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
114 if (aVM->getType() != OCCViewer_Viewer::Type())
117 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aVM)->getOCCViewer();
118 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
121 /* erase any previous */
122 ic->Erase(mySimulationShape1, Standard_True, Standard_False);
123 ic->ClearPrs(mySimulationShape1);
125 mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
126 mySimulationShape1->Set(S1);
127 mySimulationShape1->SetColor(Quantity_NOC_RED);
129 ic->Deactivate(mySimulationShape1);
130 ic->Display(mySimulationShape1, Standard_False);
131 mySimulationShape1->UnsetColor();
134 ic->Erase(mySimulationShape2, Standard_True, Standard_False);
135 ic->ClearPrs(mySimulationShape2);
137 mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
138 mySimulationShape2->Set(S2);
139 mySimulationShape2->SetColor(Quantity_NOC_VIOLET);
141 ic->Deactivate(mySimulationShape2);
142 ic->Display(mySimulationShape2, Standard_False);
143 mySimulationShape2->UnsetColor();
145 ic->UpdateCurrentViewer();
147 catch(Standard_Failure) {
148 MESSAGE("Exception catched in EntityGUI::DisplaySimulationShape ");
153 //==================================================================================
154 // function : EraseSimulationShape()
155 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
156 //==================================================================================
157 void EntityGUI::EraseSimulationShape()
159 SalomeApp_Application* app = getGeometryGUI()->getApp();
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;
167 for ( vw = aWndLst.first(); vw; vw = aWndLst.next() )
168 if ( vw->getViewManager()->study() == app->activeStudy() )
169 aWndLstAS.append( vw );
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();
184 //=====================================================================================
185 // function : SObjectExist()
187 //=====================================================================================
188 bool EntityGUI::SObjectExist(const _PTR(SObject)& theFatherObject, const char* IOR)
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;
195 _PTR(Study) aStudy = appStudy->studyDS();
196 _PTR(ChildIterator) it ( aStudy->NewChildIterator(theFatherObject) );
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)
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)
218 //=====================================================================================
220 //=====================================================================================
223 GEOM_ENTITYGUI_EXPORT
224 GEOMGUI* GetLibGUI( GeometryGUI* parent )
226 return new EntityGUI( parent );