1 // Copyright (C) 2007-2022 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 : MeasureGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "MeasureGUI.h"
29 #include <GeometryGUI.h>
30 #include "GeometryGUI_Operations.h"
31 #include <GEOMGUI_TextTreeWdg.h>
33 #include <GEOMGUI_DimensionProperty.h>
34 #include <GEOMGUI_AnnotationAttrs.h>
35 #include <GEOMGUI_AnnotationMgr.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_OverrideCursor.h>
39 #include <SUIT_Desktop.h>
40 #include <SalomeApp_Application.h>
41 #include <SalomeApp_Study.h>
43 #include "MeasureGUI_PropertiesDlg.h" // Method PROPERTIES
44 #include "MeasureGUI_CenterMassDlg.h" // Method CENTER MASS
45 #include "MeasureGUI_NormaleDlg.h" // Method NORMALE
46 #include "MeasureGUI_InertiaDlg.h" // Method INERTIA
47 #include "MeasureGUI_BndBoxDlg.h" // Method BNDBOX
48 #include "MeasureGUI_DistanceDlg.h" // Method DISTANCE
49 #include "MeasureGUI_AngleDlg.h" // Method ANGLE
50 #include "MeasureGUI_AnnotationDlg.h" // Method ANNOTATION
51 #include "MeasureGUI_MaxToleranceDlg.h" // Method MAXTOLERANCE
52 #include "MeasureGUI_WhatisDlg.h" // Method WHATIS
53 #include "MeasureGUI_CheckShapeDlg.h" // Method CHECKSHAPE
54 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h" // Method CHECKCOMPOUND
55 #include "MeasureGUI_GetNonBlocksDlg.h" // Method GET NON BLOCKS
56 #include "MeasureGUI_CheckSelfIntersectionsDlg.h" // Method CHECK SELF INTERSCTIONS
57 #include "MeasureGUI_FastCheckIntersectionsDlg.h" // Method FAST CHECK INTERSCTIONS
58 #include "MeasureGUI_PointDlg.h" // Method POINTCOORDINATES
59 #include "MeasureGUI_ManageDimensionsDlg.h" // Method MANAGEDIMENSIONS
60 #ifndef DISABLE_PLOT2DVIEWER
61 #include "MeasureGUI_ShapeStatisticsDlg.h" // Method SHAPE STATISTICS
64 #include <QApplication>
66 //=======================================================================
67 // function : MeasureGUI()
68 // purpose : Constructor
69 //=======================================================================
70 MeasureGUI::MeasureGUI( GeometryGUI* parent ) : GEOMGUI( parent )
72 myManageDimensionDlg = 0;
75 //=======================================================================
76 // function : ~MeasureGUI()
77 // purpose : Destructor
78 //=======================================================================
79 MeasureGUI::~MeasureGUI()
84 //=======================================================================
85 // function : OnGUIEvent()
87 //=======================================================================
88 bool MeasureGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
90 SalomeApp_Application* app = getGeometryGUI()->getApp();
91 if ( !app ) return false;
93 getGeometryGUI()->EmitSignalDeactivateDialog();
96 switch ( theCommandID ) {
97 case GEOMOp::OpProperties:
98 dlg = new MeasureGUI_PropertiesDlg( getGeometryGUI(), parent );
99 break; // LENGTH, AREA AND VOLUME
100 case GEOMOp::OpCenterMass:
101 dlg = new MeasureGUI_CenterMassDlg( getGeometryGUI(), parent );
102 break; // CENTER MASS7
103 case GEOMOp::OpInertia:
104 dlg = new MeasureGUI_InertiaDlg( getGeometryGUI(), parent );
106 case GEOMOp::OpNormale :
107 dlg = new MeasureGUI_NormaleDlg( getGeometryGUI(), parent );
109 case GEOMOp::OpBoundingBox:
110 dlg = new MeasureGUI_BndBoxDlg( getGeometryGUI(), parent );
111 break; // BOUNDING BOX
112 case GEOMOp::OpMinDistance:
113 dlg = new MeasureGUI_DistanceDlg( getGeometryGUI(), parent );
114 break; // MIN DISTANCE
115 case GEOMOp::OpAngle:
116 dlg = new MeasureGUI_AngleDlg( getGeometryGUI(), parent );
118 case GEOMOp::OpAnnotation:
119 dlg = new MeasureGUI_AnnotationDlg( getGeometryGUI(), true, parent );
121 case GEOMOp::OpEditAnnotation:
122 dlg = new MeasureGUI_AnnotationDlg( getGeometryGUI(), false, parent );
124 case GEOMOp::OpTolerance:
125 dlg = new MeasureGUI_MaxToleranceDlg( getGeometryGUI(), parent );
126 break; // MAXTOLERANCE
127 case GEOMOp::OpWhatIs:
128 dlg = new MeasureGUI_WhatisDlg( getGeometryGUI(), parent );
130 case GEOMOp::OpCheckShape:
131 dlg = new MeasureGUI_CheckShapeDlg( getGeometryGUI(), parent );
133 case GEOMOp::OpCheckCompound:
134 dlg = new MeasureGUI_CheckCompoundOfBlocksDlg( getGeometryGUI(), parent );
135 break; // CHECKCOMPOUND
136 case GEOMOp::OpGetNonBlocks:
137 dlg = new MeasureGUI_GetNonBlocksDlg(getGeometryGUI(), parent);
138 break; // GET NON BLOCKS
139 case GEOMOp::OpCheckSelfInters:
140 dlg = new MeasureGUI_CheckSelfIntersectionsDlg( getGeometryGUI(), parent );
141 break; // CHECK SELF INTERSCTIONS
142 case GEOMOp::OpFastCheckInters:
143 dlg = new MeasureGUI_FastCheckIntersectionsDlg( getGeometryGUI(), parent );
144 break; // FAST CHECK INTERSCTIONS
145 #ifndef DISABLE_PLOT2DVIEWER
146 case GEOMOp::OpShapeStatistics:
147 dlg = new MeasureGUI_ShapeStatisticsDlg( parent );
148 break; // SHAPE STATISTICS
150 case GEOMOp::OpPointCoordinates:
151 dlg = new MeasureGUI_PointDlg( getGeometryGUI(), parent );
152 break; // POINT COORDINATES
153 case GEOMOp::OpManageDimensions:
154 if( !myManageDimensionDlg ) {
155 dlg = new MeasureGUI_ManageDimensionsDlg( getGeometryGUI(), parent );
156 myManageDimensionDlg = dlg;
157 connect( dlg, SIGNAL( finished(int) ), this, SLOT( onFinished(int) ) );
159 myManageDimensionDlg->activateWindow();
160 break; // MANAGE DIMENSIONS
161 case GEOMOp::OpShowAllDimensions:
162 ChangeDimensionsVisibility( true );
163 break; // SHOW ALL DIMENSIONS
164 case GEOMOp::OpHideAllDimensions:
165 ChangeDimensionsVisibility( false );
166 break; // HIDE ALL DIMENSIONS
167 case GEOMOp::OpShowAllAnnotations:
168 ChangeAnnotationsVisibility( true );
169 break; // SHOW ALL ANNOTATIONS
170 case GEOMOp::OpHideAllAnnotations:
171 ChangeAnnotationsVisibility( false );
172 break; // HIDE ALL ANNOTATIONS
173 case GEOMOp::OpDeleteAnnotation:
175 break; // DELETE ANNOTATIOn
177 app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
181 dlg->updateGeometry();
182 dlg->resize( dlg->minimumSizeHint() );
188 //=======================================================================
189 // function : ChangeDimensionsVisibility
191 //=======================================================================
192 void MeasureGUI::ChangeDimensionsVisibility( const bool theIsVisible )
194 SalomeApp_Application* anApp = getGeometryGUI()->getApp();
199 Handle(SALOME_InteractiveObject) anIObject = getSingleSelectedIO();
200 if ( anIObject.IsNull()
201 || !anIObject->hasEntry() )
204 SUIT_OverrideCursor wc;
206 GEOMGUI_DimensionProperty aDimensions( QString(anIObject->getEntry()) );
208 for ( int anIt = 0; anIt < aDimensions.GetNumber(); ++anIt ) {
209 aDimensions.SetVisible( anIt, theIsVisible );
212 aDimensions.SaveToAttribute( anIObject->getEntry() );
214 GEOM_Displayer().Redisplay( anIObject, true );
217 //=======================================================================
218 // function : ChangeAnnotationsVisibility
220 //=======================================================================
221 void MeasureGUI::ChangeAnnotationsVisibility( const bool theIsVisible )
223 SalomeApp_Application* anApp = getGeometryGUI()->getApp();
227 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
228 if ( !anActiveStudy )
232 Handle(SALOME_InteractiveObject) anIObject = getSingleSelectedIO();
233 if ( !anIObject.IsNull() && anIObject->hasEntry() ) {
234 anEntry = anIObject->getEntry();
236 if ( anEntry.isEmpty() ) {
237 anEntry = getGeometryGUI()->GetTextTreeWdg()->getSingleSelectedObject();
240 if ( !anEntry.isEmpty() ) {
241 _PTR(SObject) aSObj = anActiveStudy->studyDS()->FindObjectID( anEntry.toStdString() );
243 const Handle(GEOMGUI_AnnotationAttrs)
244 aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
246 if ( aShapeAnnotations.IsNull() ) {
250 const int aCount = aShapeAnnotations->GetNbAnnotation();
254 SUIT_OverrideCursor wc;
256 for ( int anI = 0; anI < aCount; ++anI ) {
258 if ( !theIsVisible ) {
259 getGeometryGUI()->GetAnnotationMgr()->Erase( anEntry, anI );
262 getGeometryGUI()->GetAnnotationMgr()->Display( anEntry , anI );
266 getGeometryGUI()->emitAnnotationsUpdated( anEntry );
270 if ( theIsVisible ) {
271 getGeometryGUI()->GetAnnotationMgr()->DisplayAllAnnotations();
274 getGeometryGUI()->GetAnnotationMgr()->EraseAllAnnotations();
276 getGeometryGUI()->GetTextTreeWdg()->updateVisibility();
280 //=======================================================================
281 // function : DeleteAnnotation
283 //=======================================================================
284 void MeasureGUI::DeleteAnnotation()
286 SalomeApp_Application* anApp = getGeometryGUI()->getApp();
290 SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
291 if ( !anActiveStudy )
294 Handle(SALOME_InteractiveObject) anIObject = getSingleSelectedIO();
295 if ( anIObject.IsNull()
296 || !anIObject->hasEntry() )
299 const QString aEntry = anIObject->getEntry();
305 if ( getGeometryGUI()->GetAnnotationMgr()->getIndexFromEntry( aEntry, aObjEntry, aIndex ) )
307 _PTR(SObject) aSObj = anActiveStudy->studyDS()->FindObjectID( aObjEntry.toStdString() );
309 const Handle(GEOMGUI_AnnotationAttrs)
310 aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
312 if ( aShapeAnnotations.IsNull() ) {
316 aShapeAnnotations->Remove( aIndex );
318 getGeometryGUI()->GetAnnotationMgr()->EraseRemovedAnnotation( aObjEntry, aIndex );
320 getGeometryGUI()->emitAnnotationsUpdated( aObjEntry );
324 //=======================================================================
325 // function : getSingleSelectedIO
326 // purpose : returns selected interactive object for single selection.
327 //=======================================================================
328 Handle(SALOME_InteractiveObject) MeasureGUI::getSingleSelectedIO()
330 SalomeApp_Application* anApp = getGeometryGUI()->getApp();
332 return Handle(SALOME_InteractiveObject)();
335 LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
337 return Handle(SALOME_InteractiveObject)();
340 SALOME_ListIO aListIO;
341 aSelMgr->selectedObjects( aListIO );
342 if ( aListIO.Extent() != 1 ) {
343 return Handle(SALOME_InteractiveObject)();
346 return aListIO.First();
349 //=======================================================================
350 // function : onFinished
351 // purpose : called then "Manage Dimension" dialog is closed.
352 //=======================================================================
353 void MeasureGUI::onFinished(int /*theResult*/) {
354 if(sender() == myManageDimensionDlg) {
355 myManageDimensionDlg = 0;
359 //=====================================================================================
361 //=====================================================================================
365 __declspec( dllexport )
367 GEOMGUI* GetLibGUI( GeometryGUI* parent )
369 return new MeasureGUI( parent );