1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : EntityGUI.cxx
25 // Author : Damien COQUERET
29 #include "EntityGUI.h"
30 #include "GeometryGUI.h"
31 #include "GEOM_AssemblyBuilder.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_ViewWindow.h"
36 #include "OCCViewer_ViewModel.h"
37 #include "OCCViewer_ViewManager.h"
38 #include "SalomeApp_Study.h"
39 #include "SalomeApp_Tools.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 : GetEntityGUI()
55 // purpose : Get the only EntityGUI object [ static ]
56 //=======================================================================
57 EntityGUI* EntityGUI::GetEntityGUI( GeometryGUI* parent )
59 return new EntityGUI( parent );
62 //=======================================================================
63 // function : EntityGUI()
64 // purpose : Constructor
65 //=======================================================================
66 EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
68 mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
69 mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
72 //=======================================================================
73 // function : ~EntityGUI()
74 // purpose : Destructor
75 //=======================================================================
76 EntityGUI::~EntityGUI()
81 //=======================================================================
82 // function : OnGUIEvent()
84 //=======================================================================
85 bool EntityGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
87 getGeometryGUI()->EmitSignalDeactivateDialog();
93 getGeometryGUI()->ActiveWorkingPlane();
94 aDlg = new EntityGUI_SketcherDlg(getGeometryGUI(), parent, "");
96 case 407: // EXPLODE : use ic
97 aDlg = new EntityGUI_SubShapeDlg(getGeometryGUI(), parent, "");
100 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
110 //=====================================================================================
111 // function : DisplaySimulationShape()
112 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
113 //=====================================================================================
114 void EntityGUI::DisplaySimulationShape(const TopoDS_Shape& S1, const TopoDS_Shape& S2)
116 SUIT_ViewManager* aVM =
117 SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager();
118 if (aVM->getType() != OCCViewer_Viewer::Type())
121 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aVM)->getOCCViewer();
122 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
125 /* erase any previous */
126 ic->Erase(mySimulationShape1, Standard_True, Standard_False);
127 ic->ClearPrs(mySimulationShape1);
129 mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
130 mySimulationShape1->Set(S1);
131 mySimulationShape1->SetColor(Quantity_NOC_RED);
133 ic->Deactivate(mySimulationShape1);
134 ic->Display(mySimulationShape1, Standard_False);
135 mySimulationShape1->UnsetColor();
138 ic->Erase(mySimulationShape2, Standard_True, Standard_False);
139 ic->ClearPrs(mySimulationShape2);
141 mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
142 mySimulationShape2->Set(S2);
143 mySimulationShape2->SetColor(Quantity_NOC_VIOLET);
145 ic->Deactivate(mySimulationShape2);
146 ic->Display(mySimulationShape2, Standard_False);
147 mySimulationShape2->UnsetColor();
149 ic->UpdateCurrentViewer();
151 catch(Standard_Failure) {
152 MESSAGE("Exception catched in EntityGUI::DisplaySimulationShape ");
157 //==================================================================================
158 // function : EraseSimulationShape()
159 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
160 //==================================================================================
161 void EntityGUI::EraseSimulationShape()
163 // get all view windows at the desktop
164 QPtrList<SUIT_ViewWindow> aWndLst = SUIT_Session::session()->activeApplication()->desktop()->windows();
165 //get all view windows, which belong to the active study
166 QPtrList<SUIT_ViewWindow> aWndLstAS;
168 for ( vw = aWndLst.first(); vw; vw = aWndLst.next() )
169 if ( vw->getViewManager()->study() == SUIT_Session::session()->activeApplication()->activeStudy() )
170 aWndLstAS.append( vw );
172 for ( vw = aWndLstAS.first(); vw; vw = aWndLstAS.next() ) {
173 if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
174 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(vw->getViewManager()))->getOCCViewer();
175 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
176 ic->Erase(mySimulationShape1, Standard_True, Standard_False);
177 ic->ClearPrs(mySimulationShape1);
178 ic->Erase(mySimulationShape2, Standard_True, Standard_False);
179 ic->ClearPrs(mySimulationShape2);
180 ic->UpdateCurrentViewer();
185 //=====================================================================================
186 // function : SObjectExist()
188 //=====================================================================================
189 bool EntityGUI::SObjectExist(const _PTR(SObject)& theFatherObject, const char* IOR)
191 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
192 ( SUIT_Session::session()->activeApplication()->activeStudy() );
193 if ( !appStudy ) return false;
194 _PTR(Study) aStudy = appStudy->studyDS();
195 _PTR(ChildIterator) it ( aStudy->NewChildIterator(theFatherObject) );
197 _PTR(GenericAttribute) anAttr;
198 for(; it->More();it->Next()) {
199 _PTR(SObject) SO ( it->Value() );
200 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
201 _PTR(AttributeIOR) anIOR ( anAttr );
202 if(strcmp( anIOR->Value().c_str(), IOR ) == 0)
205 if(SO->ReferencedObject(RefSO)) {
206 if(RefSO->FindAttribute(anAttr, "AttributeIOR")) {
207 _PTR(AttributeIOR) anIOR ( anAttr );
208 if(strcmp(anIOR->Value().c_str(), IOR) == 0)
217 //=====================================================================================
219 //=====================================================================================
223 __declspec( dllexport )
225 GEOMGUI* GetLibGUI( GeometryGUI* parent )
227 return EntityGUI::GetEntityGUI( parent );