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>
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_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::OpExplode: // EXPLODE
111 aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
114 case GEOMOp::OpFeatureDetect: // FEATURE DETECTION
115 aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent );
118 case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER
119 aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent );
121 case GEOMOp::OpCreateField: // CREATE FIELD
122 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), GEOM::GEOM_Field::_nil(), 0,
125 case GEOMOp::OpEditField: // EDIT FIELD
126 case GEOMOp::OpEditFieldPopup:
131 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
133 aSelMgr->selectedObjects(aList);
134 SALOME_ListIteratorOfListIO anIter (aList);
136 GEOM::GEOM_Field_var field;
137 GEOM::GEOM_FieldStep_var step;
139 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
140 if ( aList.Extent() > 0 && study ) {
141 for ( ; anIter.More(); anIter.Next() )
143 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
144 if ( !anIObj.IsNull() && anIObj->hasEntry() )
145 if ( _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() ))
147 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
148 GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
149 GEOM::GEOM_Field_var f;
150 GEOM::GEOM_FieldStep_var s;
151 switch ( bo->GetType() ) {
153 f = GEOM::GEOM_Field::_narrow( corbaObj ); break;
154 case GEOM_FIELD_STEP:
155 step = GEOM::GEOM_FieldStep::_narrow( corbaObj );
156 if ( !step->_is_nil() )
157 f = step->GetField();
164 if ( !field->_is_nil() && !f->_is_equivalent( field ))
166 field = GEOM::GEOM_Field::_nil(); // several field selected
175 if ( !field->_is_nil()) {
177 if ( !step->_is_nil() ) {
178 stepID = step->GetID();
181 GEOM::ListOfLong_var stepIDs = field->GetSteps();
182 if ( stepIDs->length() > 0 )
187 aDlg = new EntityGUI_FieldDlg (getGeometryGUI(), field, stepID, parent);
190 SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
193 case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
194 getGeometryGUI()->ActiveWorkingPlane();
195 aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
198 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
207 //=================================================================================
208 // function : 0nMousePress()
209 // purpose : [static] manage mouse events
210 //=================================================================================
211 bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
213 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
215 // Create Point dialog, OCC viewer
217 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
218 pe->modifiers() != Qt::ControlModifier ) {
222 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 )
224 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
225 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(true);
226 if ( aSketcherDlg->acceptMouseEvent() ) {
227 OCCViewer_Viewer* anOCCViewer =
228 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
229 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
232 if ( pe->modifiers() == Qt::ShiftModifier )
233 ic->ShiftSelect(); // Append selection
235 ic->Select(); // New selection
238 if ( ic->MoreSelected() ) {
239 TopoDS_Shape aShape = ic->SelectedShape();
240 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
241 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
244 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
245 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
248 Qt::KeyboardModifiers modifiers = pe->modifiers();
249 aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
250 } // acceptMouseEvent()
253 if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 )
255 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
256 if ( aCornerDlg->acceptMouseEvent() ) {
257 OCCViewer_Viewer* anOCCViewer =
258 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
259 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
262 ic->Select(); // New selection
266 if ( ic->MoreSelected() )
267 aShape = ic->SelectedShape();
268 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
269 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
272 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
273 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
276 // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
278 // QPoint start = QPoint(pe->x(),pe->y());
279 aCornerDlg->setStartPnt( aPnt );
280 } // acceptMouseEvent()
289 //=================================================================================
290 // function : 0nMouseRelease()
291 // purpose : [static] manage mouse events
292 //=================================================================================
293 bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
295 ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
296 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
298 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
299 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
300 pe->modifiers() != Qt::ControlModifier )
302 EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
306 if ( aCornerDlg->acceptMouseEvent() )
308 // QPoint end = QPoint(pe->x(),pe->y());
309 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
310 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
311 aCornerDlg->setEndPnt( aPnt );
318 //=================================================================================
319 // function : 0nMouseMove()
320 // purpose : [static] manage mouse events
321 //=================================================================================
322 bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
324 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
326 if ( aDlg && QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 &&
327 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() )
329 EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg;
330 if ( aSketcherDlg->acceptMouseEvent() )
332 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
333 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
335 Qt::KeyboardModifiers modifiers = pe->modifiers();
336 if (QApplication::mouseButtons() == Qt::LeftButton )
337 aSketcherDlg->OnPointSelected( modifiers, aPnt, false ); // "feed" the point to point construction dialog
344 //=====================================================================================
345 // function : DisplaySimulationShape()
346 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
347 //=====================================================================================
348 void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
350 MESSAGE("EntityGUI::DisplaySimulationShape")
351 SalomeApp_Application* app = getGeometryGUI()->getApp();
354 SUIT_ViewManager* aVM = app->desktop()->activeWindow()->getViewManager();
355 if ( aVM->getType() != OCCViewer_Viewer::Type() )
358 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)aVM )->getOCCViewer();
359 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
361 if ( !S1.IsNull() ) {
362 /* erase any previous */
363 ic->Erase( mySimulationShape1, Standard_True );
364 ic->ClearPrs( mySimulationShape1 );
366 mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
367 mySimulationShape1->Set( S1 );
368 mySimulationShape1->SetColor( Quantity_NOC_RED );
370 ic->Deactivate( mySimulationShape1 );
371 ic->Display( mySimulationShape1, Standard_False );
372 mySimulationShape1->UnsetColor();
374 if ( !S2.IsNull() ) {
375 ic->Erase( mySimulationShape2, Standard_True );
376 ic->ClearPrs( mySimulationShape2 );
378 mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
379 mySimulationShape2->Set( S2 );
380 mySimulationShape2->SetColor( Quantity_NOC_VIOLET );
382 ic->Deactivate( mySimulationShape2 );
383 ic->Display( mySimulationShape2, Standard_False );
384 mySimulationShape2->UnsetColor();
386 ic->UpdateCurrentViewer();
388 catch( Standard_Failure ) {
389 MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
393 //==================================================================================
394 // function : EraseSimulationShape()
395 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
396 //==================================================================================
397 void EntityGUI::EraseSimulationShape()
399 MESSAGE("EntityGUI::EraseSimulationShape")
400 SalomeApp_Application* app = getGeometryGUI()->getApp();
403 // get all view windows at the desktop
404 QList<SUIT_ViewWindow*> aWndLst = app->desktop()->windows();
405 //get all view windows, which belong to the active study
406 QList<SUIT_ViewWindow*> aWndLstAS;
409 QListIterator<SUIT_ViewWindow*> itWL( aWndLst );
410 while ( itWL.hasNext() && ( vw = itWL.next() ) )
411 if ( vw->getViewManager()->study() == app->activeStudy() )
412 aWndLstAS.append( vw );
414 QListIterator<SUIT_ViewWindow*> itWLAS( aWndLstAS );
415 while ( itWLAS.hasNext() && ( vw = itWLAS.next() ) ) {
416 if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
417 OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
418 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
419 ic->Erase( mySimulationShape1, Standard_True );
420 ic->Erase( mySimulationShape2, Standard_True );
421 ic->ClearPrs( mySimulationShape1 );
422 ic->ClearPrs( mySimulationShape2 );
423 ic->UpdateCurrentViewer();
428 //=====================================================================================
429 // function : SObjectExist()
431 //=====================================================================================
432 bool EntityGUI::SObjectExist( const _PTR(SObject)& theFatherObject, const char* IOR )
434 SalomeApp_Application* app = getGeometryGUI()->getApp();
435 if ( !app ) return false;
436 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
437 if ( !appStudy ) return false;
439 _PTR(Study) aStudy = appStudy->studyDS();
440 _PTR(ChildIterator) it ( aStudy->NewChildIterator( theFatherObject ) );
442 _PTR(GenericAttribute) anAttr;
443 for ( ; it->More();it->Next() ) {
444 _PTR(SObject) SO ( it->Value() );
445 if ( SO->FindAttribute( anAttr, "AttributeIOR" ) ) {
446 _PTR(AttributeIOR) anIOR ( anAttr );
447 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
450 if ( SO->ReferencedObject( RefSO ) ) {
451 if ( RefSO->FindAttribute( anAttr, "AttributeIOR" ) ) {
452 _PTR(AttributeIOR) anIOR ( anAttr );
453 if ( strcmp( anIOR->Value().c_str(), IOR ) == 0 )
462 //=====================================================================================
464 //=====================================================================================
468 __declspec( dllexport )
470 GEOMGUI* GetLibGUI( GeometryGUI* parent )
472 return new EntityGUI( parent );