1 // Copyright (C) 2007-2020 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() );
145 for ( ; anIter.More(); anIter.Next() )
147 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
148 if ( !anIObj.IsNull() && anIObj->hasEntry() )
150 _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() );
151 if ( GeometryGUI::IsInGeomComponent( obj ))
153 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
154 GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
155 GEOM::GEOM_Field_var f;
156 GEOM::GEOM_FieldStep_var s;
157 switch ( bo->GetType() ) {
159 f = GEOM::GEOM_Field::_narrow( corbaObj ); break;
160 case GEOM_FIELD_STEP:
161 step = GEOM::GEOM_FieldStep::_narrow( corbaObj );
162 if ( !step->_is_nil() )
163 f = step->GetField();
170 if ( !field->_is_nil() && !f->_is_equivalent( field ))
172 field = GEOM::GEOM_Field::_nil(); // several field selected
180 if ( !field->_is_nil()) {
182 if ( !step->_is_nil() ) {
183 stepID = step->GetID();
186 GEOM::ListOfLong_var stepIDs = field->GetSteps();
187 if ( stepIDs->length() > 0 )
192 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), field, stepID, parent);
195 SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
198 case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
199 getGeometryGUI()->ActiveWorkingPlane();
200 aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
203 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
212 //=================================================================================
213 // function : 0nMousePress()
214 // purpose : [static] manage mouse events
215 //=================================================================================
216 bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
218 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
220 // Create Point dialog, OCC viewer
222 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
223 pe->modifiers() != Qt::ControlModifier ) {
227 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 )
229 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
230 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
231 if ( aSketcherDlg->acceptMouseEvent() ) {
232 OCCViewer_Viewer* anOCCViewer =
233 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
234 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
237 if ( pe->modifiers() == Qt::ShiftModifier )
238 ic->ShiftSelect( Standard_True ); // Append selection
240 ic->Select( Standard_True ); // New selection
243 if ( ic->MoreSelected() ) {
244 TopoDS_Shape aShape = ic->SelectedShape();
245 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
246 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
249 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
250 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
253 Qt::KeyboardModifiers modifiers = pe->modifiers();
254 aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
255 } // acceptMouseEvent()
258 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 )
260 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
261 if ( aCornerDlg->acceptMouseEvent() ) {
262 OCCViewer_Viewer* anOCCViewer =
263 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
264 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
267 ic->Select( Standard_True ); // New selection
271 if ( ic->MoreSelected() )
272 aShape = ic->SelectedShape();
273 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
274 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
277 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
278 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
281 // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
283 // QPoint start = QPoint(pe->x(),pe->y());
284 aCornerDlg->setStartPnt( aPnt );
285 } // acceptMouseEvent()
294 //=================================================================================
295 // function : 0nMouseRelease()
296 // purpose : [static] manage mouse events
297 //=================================================================================
298 bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
300 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
302 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
303 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
304 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
305 pe->modifiers() != Qt::ControlModifier )
307 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
311 if ( aCornerDlg->acceptMouseEvent() )
313 // QPoint end = QPoint(pe->x(),pe->y());
314 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
315 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
316 aCornerDlg->setEndPnt( aPnt );
323 //=================================================================================
324 // function : 0nMouseMove()
325 // purpose : [static] manage mouse events
326 //=================================================================================
327 bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
329 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
331 if ( aDlg && QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 &&
332 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() )
334 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
335 if ( aSketcherDlg->acceptMouseEvent() )
337 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
338 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
340 Qt::KeyboardModifiers modifiers = pe->modifiers();
341 if (QApplication::mouseButtons() == Qt::LeftButton )
342 aSketcherDlg->OnPointSelected( modifiers, aPnt, false ); // "feed" the point to point construction dialog
349 //=====================================================================================
350 // function : DisplaySimulationShape()
351 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
352 //=====================================================================================
353 void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
355 MESSAGE("EntityGUI::DisplaySimulationShape")
356 SalomeApp_Application* app = getGeometryGUI()->getApp();
359 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
360 if ( aVM->getType() != OCCViewer_Viewer::Type() )
363 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
364 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
366 if ( !S1.IsNull() ) {
367 /* erase any previous */
368 ic->Erase( mySimulationShape1, Standard_True );
369 ic->ClearPrs( mySimulationShape1, 0, Standard_True );
371 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
372 mySimulationShape1->Set( S1 );
373 mySimulationShape1->SetColor( Quantity_NOC_RED );
375 ic->Deactivate( mySimulationShape1 );
376 ic->Display( mySimulationShape1, Standard_False );
377 mySimulationShape1->UnsetColor();
379 if ( !S2.IsNull() ) {
380 ic->Erase( mySimulationShape2, Standard_True );
381 ic->ClearPrs( mySimulationShape2, 0, Standard_True );
383 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
384 mySimulationShape2->Set( S2 );
385 mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
387 ic->Deactivate( mySimulationShape2 );
388 ic->Display( mySimulationShape2, Standard_False );
389 mySimulationShape2->UnsetColor();
391 ic->UpdateCurrentViewer();
393 catch( Standard_Failure ) {
394 MESSAGE( "Exception caught in EntityGUI::DisplaySimulationShape" );
398 //==================================================================================
399 // function : EraseSimulationShape()
400 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
401 //==================================================================================
402 void EntityGUI::EraseSimulationShape()
404 MESSAGE("EntityGUI::EraseSimulationShape")
405 SalomeApp_Application* app = getGeometryGUI()->getApp();
408 // get all view windows at the desktop
409 QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
410 //get all view windows, which belong to the active study
411 QList<SUIT_ViewWindow*> aWndLstAS;
414 QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
415 while ( itWL.hasNext() && ( vw = itWL.next() ) )
416 if ( vw->getViewManager()->study() == app->activeStudy() )
417 aWndLstAS.append( vw );
419 QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
420 while ( itWLAS.hasNext() && ( vw = itWLAS.next() ) ) {
421 if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
422 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
423 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
424 ic->Erase( mySimulationShape1, Standard_True );
425 ic->Erase( mySimulationShape2, Standard_True );
426 ic->ClearPrs( mySimulationShape1, 0, Standard_True );
427 ic->ClearPrs( mySimulationShape2, 0, Standard_True );
428 ic->UpdateCurrentViewer();
433 //=====================================================================================
434 // function : SObjectExist()
436 //=====================================================================================
437 bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
439 SalomeApp_Application* app = getGeometryGUI()->getApp();
440 if ( !app ) return false;
441 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
442 if ( !appStudy ) return false;
444 _PTR(Study) aStudy = appStudy->studyDS();
445 _PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
447 _PTR(GenericAttribute) anAttr;
448 for ( ; it->More();it->Next() ) {
449 _PTR(SObject) SO ( it->Value() );
450 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) ) {
451 _PTR(AttributeIOR) anIOR ( anAttr );
452 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
455 if ( SO->ReferencedObject( RefSO ) ) {
456 if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
457 _PTR(AttributeIOR) anIOR ( anAttr );
458 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
467 //=====================================================================================
469 //=====================================================================================
473 __declspec( dllexport )
475 GEOMGUI* GetLibGUI( GeometryGUI* parent )
477 return new EntityGUI( parent );