1 // Copyright (C) 2007-2014 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>
46 #include <TopoDS_Shape.hxx>
48 #include <BRep_Tool.hxx>
49 #include <ProjLib.hxx>
52 #include <QMouseEvent>
53 #include <QApplication>
55 #include "EntityGUI_SketcherDlg.h" // Sketcher
56 #include "EntityGUI_3DSketcherDlg.h" // Sketcher
57 #include "EntityGUI_IsolineDlg.h" // Isoline
58 #include "EntityGUI_SurfFromFaceDlg.h" // Surface From Face
59 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
60 #include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection
61 #include "EntityGUI_PictureImportDlg.h" // Import Picture in viewer
62 #include "EntityGUI_FieldDlg.h" // Create/Edit Field
63 #include "EntityGUI_PolylineDlg.h" // Create/Edit 2d polyline
65 #include "GEOMImpl_Types.hxx"
68 //=======================================================================
69 // function : EntityGUI()
70 // purpose : Constructor
71 //=======================================================================
72 EntityGUI::EntityGUI( GeometryGUI* parent ) : GEOMGUI( parent )
74 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
75 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
78 //=======================================================================
79 // function : ~EntityGUI()
80 // purpose : Destructor
81 //=======================================================================
82 EntityGUI::~EntityGUI()
87 //=======================================================================
88 // function : OnGUIEvent()
90 //=======================================================================
91 bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
93 SalomeApp_Application* app = getGeometryGUI()->getApp();
94 if ( !app ) return false;
96 getGeometryGUI()->EmitSignalDeactivateDialog();
99 switch ( theCommandID ) {
100 case GEOMOp::Op2dSketcher: // 2D SKETCHER
101 getGeometryGUI()->ActiveWorkingPlane();
102 aDlg = new EntityGUI_SketcherDlg( getGeometryGUI(), parent );
104 case GEOMOp::Op3dSketcher: // 3D SKETCHER
105 aDlg = new EntityGUI_3DSketcherDlg( getGeometryGUI(), parent );
107 case GEOMOp::OpIsoline: // ISOLINE
108 aDlg = new EntityGUI_IsolineDlg( getGeometryGUI(), parent );
110 case GEOMOp::OpSurfaceFromFace: // SURFACE FROM FACE
111 aDlg = new EntityGUI_SurfFromFaceDlg( getGeometryGUI(), parent );
113 case GEOMOp::OpExplode: // EXPLODE
114 aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
117 case GEOMOp::OpFeatureDetect: // FEATURE DETECTION
118 aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent );
121 case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER
122 aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent );
124 case GEOMOp::OpCreateField: // CREATE FIELD
125 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), GEOM::GEOM_Field::_nil(), 0,
128 case GEOMOp::OpEditField: // EDIT FIELD
129 case GEOMOp::OpEditFieldPopup:
134 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
136 aSelMgr->selectedObjects(aList);
137 SALOME_ListIteratorOfListIO anIter (aList);
139 GEOM::GEOM_Field_var field;
140 GEOM::GEOM_FieldStep_var step;
142 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
143 if ( aList.Extent() > 0 && study ) {
144 for ( ; anIter.More(); anIter.Next() )
146 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
147 if ( !anIObj.IsNull() && anIObj->hasEntry() )
148 if ( _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() ))
150 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
151 GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
152 GEOM::GEOM_Field_var f;
153 GEOM::GEOM_FieldStep_var s;
154 switch ( bo->GetType() ) {
156 f = GEOM::GEOM_Field::_narrow( corbaObj ); break;
157 case GEOM_FIELD_STEP:
158 step = GEOM::GEOM_FieldStep::_narrow( corbaObj );
159 if ( !step->_is_nil() )
160 f = step->GetField();
167 if ( !field->_is_nil() && !f->_is_equivalent( field ))
169 field = GEOM::GEOM_Field::_nil(); // several field selected
178 if ( !field->_is_nil()) {
180 if ( !step->_is_nil() ) {
181 stepID = step->GetID();
184 GEOM::ListOfLong_var stepIDs = field->GetSteps();
185 if ( stepIDs->length() > 0 )
190 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), field, stepID, parent);
193 SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
196 case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
197 getGeometryGUI()->ActiveWorkingPlane();
198 aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
201 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
210 //=================================================================================
211 // function : 0nMousePress()
212 // purpose : [static] manage mouse events
213 //=================================================================================
214 bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
216 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
218 // Create Point dialog, OCC viewer
220 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
221 pe->modifiers() != Qt::ControlModifier ) {
225 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 )
227 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
228 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
229 if ( aSketcherDlg->acceptMouseEvent() ) {
230 OCCViewer_Viewer* anOCCViewer =
231 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
232 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
235 if ( pe->modifiers() == Qt::ShiftModifier )
236 ic->ShiftSelect(); // Append selection
238 ic->Select(); // New selection
241 if ( ic->MoreSelected() ) {
242 TopoDS_Shape aShape = ic->SelectedShape();
243 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
244 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
247 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
248 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
251 Qt::KeyboardModifiers modifiers = pe->modifiers();
252 aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
253 } // acceptMouseEvent()
256 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 )
258 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
259 if ( aCornerDlg->acceptMouseEvent() ) {
260 OCCViewer_Viewer* anOCCViewer =
261 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
262 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
265 ic->Select(); // New selection
269 if ( ic->MoreSelected() )
270 aShape = ic->SelectedShape();
271 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
272 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
275 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
276 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
279 // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
281 // QPoint start = QPoint(pe->x(),pe->y());
282 aCornerDlg->setStartPnt( aPnt );
283 } // acceptMouseEvent()
292 //=================================================================================
293 // function : 0nMouseRelease()
294 // purpose : [static] manage mouse events
295 //=================================================================================
296 bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
298 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
299 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
301 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
302 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
303 pe->modifiers() != Qt::ControlModifier )
305 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
309 if ( aCornerDlg->acceptMouseEvent() )
311 // QPoint end = QPoint(pe->x(),pe->y());
312 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
313 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
314 aCornerDlg->setEndPnt( aPnt );
321 //=================================================================================
322 // function : 0nMouseMove()
323 // purpose : [static] manage mouse events
324 //=================================================================================
325 bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
327 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
329 if ( aDlg && QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 &&
330 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() )
332 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
333 if ( aSketcherDlg->acceptMouseEvent() )
335 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
336 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
338 Qt::KeyboardModifiers modifiers = pe->modifiers();
339 if (QApplication::mouseButtons() == Qt::LeftButton )
340 aSketcherDlg->OnPointSelected( modifiers, aPnt, false ); // "feed" the point to point construction dialog
347 //=====================================================================================
348 // function : DisplaySimulationShape()
349 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
350 //=====================================================================================
351 void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
353 MESSAGE("EntityGUI::DisplaySimulationShape")
354 SalomeApp_Application* app = getGeometryGUI()->getApp();
357 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
358 if ( aVM->getType() != OCCViewer_Viewer::Type() )
361 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
362 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
364 if ( !S1.IsNull() ) {
365 /* erase any previous */
366 ic->Erase( mySimulationShape1, Standard_True );
367 ic->ClearPrs( mySimulationShape1 );
369 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
370 mySimulationShape1->Set( S1 );
371 mySimulationShape1->SetColor( Quantity_NOC_RED );
373 ic->Deactivate( mySimulationShape1 );
374 ic->Display( mySimulationShape1, Standard_False );
375 mySimulationShape1->UnsetColor();
377 if ( !S2.IsNull() ) {
378 ic->Erase( mySimulationShape2, Standard_True );
379 ic->ClearPrs( mySimulationShape2 );
381 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
382 mySimulationShape2->Set( S2 );
383 mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
385 ic->Deactivate( mySimulationShape2 );
386 ic->Display( mySimulationShape2, Standard_False );
387 mySimulationShape2->UnsetColor();
389 ic->UpdateCurrentViewer();
391 catch( Standard_Failure ) {
392 MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
396 //==================================================================================
397 // function : EraseSimulationShape()
398 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
399 //==================================================================================
400 void EntityGUI::EraseSimulationShape()
402 MESSAGE("EntityGUI::EraseSimulationShape")
403 SalomeApp_Application* app = getGeometryGUI()->getApp();
406 // get all view windows at the desktop
407 QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
408 //get all view windows, which belong to the active study
409 QList<SUIT_ViewWindow*> aWndLstAS;
412 QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
413 while ( itWL.hasNext() && ( vw = itWL.next() ) )
414 if ( vw->getViewManager()->study() == app->activeStudy() )
415 aWndLstAS.append( vw );
417 QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
418 while ( itWLAS.hasNext() && ( vw = itWLAS.next() ) ) {
419 if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
420 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
421 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
422 ic->Erase( mySimulationShape1, Standard_True );
423 ic->Erase( mySimulationShape2, Standard_True );
424 ic->ClearPrs( mySimulationShape1 );
425 ic->ClearPrs( mySimulationShape2 );
426 ic->UpdateCurrentViewer();
431 //=====================================================================================
432 // function : SObjectExist()
434 //=====================================================================================
435 bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
437 SalomeApp_Application* app = getGeometryGUI()->getApp();
438 if ( !app ) return false;
439 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
440 if ( !appStudy ) return false;
442 _PTR(Study) aStudy = appStudy->studyDS();
443 _PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
445 _PTR(GenericAttribute) anAttr;
446 for ( ; it->More();it->Next() ) {
447 _PTR(SObject) SO ( it->Value() );
448 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) ) {
449 _PTR(AttributeIOR) anIOR ( anAttr );
450 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
453 if ( SO->ReferencedObject( RefSO ) ) {
454 if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
455 _PTR(AttributeIOR) anIOR ( anAttr );
456 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
465 //=====================================================================================
467 //=====================================================================================
471 __declspec( dllexport )
473 GEOMGUI* GetLibGUI( GeometryGUI* parent )
475 return new EntityGUI( parent );