1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
31 #include "GEOMUtils.hxx"
33 #include <LightApp_SelectionMgr.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewPort3d.h>
37 #include <OCCViewer_ViewWindow.h>
38 #include <SALOME_ListIO.hxx>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ViewWindow.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include "utilities.h"
47 #include <TopoDS_Shape.hxx>
49 #include <BRep_Tool.hxx>
50 #include <ProjLib.hxx>
53 #include <QMouseEvent>
54 #include <QApplication>
56 #include "EntityGUI_SketcherDlg.h" // Sketcher
57 #include "EntityGUI_3DSketcherDlg.h" // Sketcher
58 #include "EntityGUI_IsolineDlg.h" // Isoline
59 #include "EntityGUI_SurfFromFaceDlg.h" // Surface From Face
60 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
61 #include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection
62 #include "EntityGUI_PictureImportDlg.h" // Import Picture in viewer
63 #include "EntityGUI_FieldDlg.h" // Create/Edit Field
64 #include "EntityGUI_PolylineDlg.h" // Create/Edit 2d polyline
66 #include "GEOMImpl_Types.hxx"
69 //=======================================================================
70 // function : EntityGUI()
71 // purpose : Constructor
72 //=======================================================================
73 EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
75 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
76 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
79 //=======================================================================
80 // function : ~EntityGUI()
81 // purpose : Destructor
82 //=======================================================================
83 EntityGUI::~EntityGUI()
88 //=======================================================================
89 // function : OnGUIEvent()
91 //=======================================================================
92 bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
94 SalomeApp_Application* app = getGeometryGUI()->getApp();
95 if ( !app ) return false;
97 getGeometryGUI()->EmitSignalDeactivateDialog();
100 switch ( theCommandID ) {
101 case GEOMOp::Op2dSketcher: // 2D SKETCHER
102 getGeometryGUI()->ActiveWorkingPlane();
103 aDlg = new EntityGUI_SketcherDlg( getGeometryGUI(), parent );
105 case GEOMOp::Op3dSketcher: // 3D SKETCHER
106 aDlg = new EntityGUI_3DSketcherDlg( getGeometryGUI(), parent );
108 case GEOMOp::OpIsoline: // ISOLINE
109 aDlg = new EntityGUI_IsolineDlg( getGeometryGUI(), parent );
111 case GEOMOp::OpSurfaceFromFace: // SURFACE FROM FACE
112 aDlg = new EntityGUI_SurfFromFaceDlg( getGeometryGUI(), parent );
114 case GEOMOp::OpExplode: // EXPLODE
115 aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
118 case GEOMOp::OpFeatureDetect: // FEATURE DETECTION
119 aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent );
122 case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER
123 aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent );
125 case GEOMOp::OpCreateField: // CREATE FIELD
126 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), GEOM::GEOM_Field::_nil(), 0,
129 case GEOMOp::OpEditField: // EDIT FIELD
130 case GEOMOp::OpEditFieldPopup:
135 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
137 aSelMgr->selectedObjects(aList);
138 SALOME_ListIteratorOfListIO anIter (aList);
140 GEOM::GEOM_Field_var field;
141 GEOM::GEOM_FieldStep_var step;
143 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
144 if ( aList.Extent() > 0 && study ) {
145 for ( ; anIter.More(); anIter.Next() )
147 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
148 if ( !anIObj.IsNull() && anIObj->hasEntry() )
149 if ( _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() ))
151 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
152 GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
153 GEOM::GEOM_Field_var f;
154 GEOM::GEOM_FieldStep_var s;
155 switch ( bo->GetType() ) {
157 f = GEOM::GEOM_Field::_narrow( corbaObj ); break;
158 case GEOM_FIELD_STEP:
159 step = GEOM::GEOM_FieldStep::_narrow( corbaObj );
160 if ( !step->_is_nil() )
161 f = step->GetField();
168 if ( !field->_is_nil() && !f->_is_equivalent( field ))
170 field = GEOM::GEOM_Field::_nil(); // several field selected
179 if ( !field->_is_nil()) {
181 if ( !step->_is_nil() ) {
182 stepID = step->GetID();
185 GEOM::ListOfLong_var stepIDs = field->GetSteps();
186 if ( stepIDs->length() > 0 )
191 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), field, stepID, parent);
194 SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
197 case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
198 getGeometryGUI()->ActiveWorkingPlane();
199 aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
202 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
211 //=================================================================================
212 // function : 0nMousePress()
213 // purpose : [static] manage mouse events
214 //=================================================================================
215 bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
217 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
219 // Create Point dialog, OCC viewer
221 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
222 pe->modifiers() != Qt::ControlModifier ) {
226 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 )
228 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
229 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
230 if ( aSketcherDlg->acceptMouseEvent() ) {
231 OCCViewer_Viewer* anOCCViewer =
232 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
233 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
236 if ( pe->modifiers() == Qt::ShiftModifier )
237 ic->ShiftSelect(); // Append selection
239 ic->Select(); // New selection
242 if ( ic->MoreSelected() ) {
243 TopoDS_Shape aShape = ic->SelectedShape();
244 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
245 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
248 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
249 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
252 Qt::KeyboardModifiers modifiers = pe->modifiers();
253 aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
254 } // acceptMouseEvent()
257 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 )
259 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
260 if ( aCornerDlg->acceptMouseEvent() ) {
261 OCCViewer_Viewer* anOCCViewer =
262 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
263 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
266 ic->Select(); // New selection
270 if ( ic->MoreSelected() )
271 aShape = ic->SelectedShape();
272 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
273 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
276 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
277 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
280 // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
282 // QPoint start = QPoint(pe->x(),pe->y());
283 aCornerDlg->setStartPnt( aPnt );
284 } // acceptMouseEvent()
293 //=================================================================================
294 // function : 0nMouseRelease()
295 // purpose : [static] manage mouse events
296 //=================================================================================
297 bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
299 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
300 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
302 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
303 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
304 pe->modifiers() != Qt::ControlModifier )
306 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
310 if ( aCornerDlg->acceptMouseEvent() )
312 // QPoint end = QPoint(pe->x(),pe->y());
313 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
314 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
315 aCornerDlg->setEndPnt( aPnt );
322 //=================================================================================
323 // function : 0nMouseMove()
324 // purpose : [static] manage mouse events
325 //=================================================================================
326 bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
328 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
330 if ( aDlg && QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 &&
331 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() )
333 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
334 if ( aSketcherDlg->acceptMouseEvent() )
336 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
337 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
339 Qt::KeyboardModifiers modifiers = pe->modifiers();
340 if (QApplication::mouseButtons() == Qt::LeftButton )
341 aSketcherDlg->OnPointSelected( modifiers, aPnt, false ); // "feed" the point to point construction dialog
348 //=====================================================================================
349 // function : DisplaySimulationShape()
350 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
351 //=====================================================================================
352 void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
354 MESSAGE("EntityGUI::DisplaySimulationShape")
355 SalomeApp_Application* app = getGeometryGUI()->getApp();
358 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
359 if ( aVM->getType() != OCCViewer_Viewer::Type() )
362 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
363 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
365 if ( !S1.IsNull() ) {
366 /* erase any previous */
367 ic->Erase( mySimulationShape1, Standard_True );
368 ic->ClearPrs( mySimulationShape1 );
370 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
371 mySimulationShape1->Set( S1 );
372 mySimulationShape1->SetColor( Quantity_NOC_RED );
374 ic->Deactivate( mySimulationShape1 );
375 ic->Display( mySimulationShape1, Standard_False );
376 mySimulationShape1->UnsetColor();
378 if ( !S2.IsNull() ) {
379 ic->Erase( mySimulationShape2, Standard_True );
380 ic->ClearPrs( mySimulationShape2 );
382 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
383 mySimulationShape2->Set( S2 );
384 mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
386 ic->Deactivate( mySimulationShape2 );
387 ic->Display( mySimulationShape2, Standard_False );
388 mySimulationShape2->UnsetColor();
390 ic->UpdateCurrentViewer();
392 catch( Standard_Failure ) {
393 MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
397 //==================================================================================
398 // function : EraseSimulationShape()
399 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
400 //==================================================================================
401 void EntityGUI::EraseSimulationShape()
403 MESSAGE("EntityGUI::EraseSimulationShape")
404 SalomeApp_Application* app = getGeometryGUI()->getApp();
407 // get all view windows at the desktop
408 QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
409 //get all view windows, which belong to the active study
410 QList<SUIT_ViewWindow*> aWndLstAS;
413 QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
414 while ( itWL.hasNext() && ( vw = itWL.next() ) )
415 if ( vw->getViewManager()->study() == app->activeStudy() )
416 aWndLstAS.append( vw );
418 QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
419 while ( itWLAS.hasNext() && ( vw = itWLAS.next() ) ) {
420 if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
421 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
422 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
423 ic->Erase( mySimulationShape1, Standard_True );
424 ic->Erase( mySimulationShape2, Standard_True );
425 ic->ClearPrs( mySimulationShape1 );
426 ic->ClearPrs( mySimulationShape2 );
427 ic->UpdateCurrentViewer();
432 //=====================================================================================
433 // function : SObjectExist()
435 //=====================================================================================
436 bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
438 SalomeApp_Application* app = getGeometryGUI()->getApp();
439 if ( !app ) return false;
440 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
441 if ( !appStudy ) return false;
443 _PTR(Study) aStudy = appStudy->studyDS();
444 _PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
446 _PTR(GenericAttribute) anAttr;
447 for ( ; it->More();it->Next() ) {
448 _PTR(SObject) SO ( it->Value() );
449 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) ) {
450 _PTR(AttributeIOR) anIOR ( anAttr );
451 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
454 if ( SO->ReferencedObject( RefSO ) ) {
455 if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
456 _PTR(AttributeIOR) anIOR ( anAttr );
457 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
466 //=====================================================================================
468 //=====================================================================================
472 __declspec( dllexport )
474 GEOMGUI* GetLibGUI( GeometryGUI* parent )
476 return new EntityGUI( parent );