Salome HOME
38a6f3be71dbdd6152e3fe3d380825664adeabad
[modules/geom.git] / src / MeasureGUI / MeasureGUI.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26
27 #include "MeasureGUI.h"
28
29 #include <GeometryGUI.h>
30 #include "GeometryGUI_Operations.h"
31
32 #include <GEOMGUI_DimensionProperty.h>
33
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_OverrideCursor.h>
36 #include <SUIT_Desktop.h>
37 #include <SalomeApp_Application.h>
38 #include <SalomeApp_Study.h>
39
40 #include "MeasureGUI_PropertiesDlg.h"             // Method PROPERTIES
41 #include "MeasureGUI_CenterMassDlg.h"             // Method CENTER MASS
42 #include "MeasureGUI_NormaleDlg.h"                // Method NORMALE
43 #include "MeasureGUI_InertiaDlg.h"                // Method INERTIA
44 #include "MeasureGUI_BndBoxDlg.h"                 // Method BNDBOX
45 #include "MeasureGUI_DistanceDlg.h"               // Method DISTANCE
46 #include "MeasureGUI_AngleDlg.h"                  // Method ANGLE
47 #include "MeasureGUI_MaxToleranceDlg.h"           // Method MAXTOLERANCE
48 #include "MeasureGUI_WhatisDlg.h"                 // Method WHATIS
49 #include "MeasureGUI_CheckShapeDlg.h"             // Method CHECKSHAPE
50 #include "MeasureGUI_CheckCompoundOfBlocksDlg.h"  // Method CHECKCOMPOUND
51 #include "MeasureGUI_GetNonBlocksDlg.h"           // Method GET NON BLOCKS
52 #include "MeasureGUI_CheckSelfIntersectionsDlg.h" // Method CHECK SELF INTERSCTIONS
53 #include "MeasureGUI_FastCheckIntersectionsDlg.h" // Method FAST CHECK INTERSCTIONS
54 #include "MeasureGUI_PointDlg.h"                  // Method POINTCOORDINATES
55 #include "MeasureGUI_ManageDimensionsDlg.h"       // Method MANAGEDIMENSIONS
56 #ifndef DISABLE_PLOT2DVIEWER
57 #include "MeasureGUI_ShapeStatisticsDlg.h"        // Method SHAPE STATISTICS
58 #endif
59
60 #include <QApplication>
61
62 //=======================================================================
63 // function : MeasureGUI()
64 // purpose  : Constructor
65 //=======================================================================
66 MeasureGUI::MeasureGUI( GeometryGUI* parent ) : GEOMGUI( parent )
67 {
68   myManageDimensionDlg = 0;
69 }
70
71 //=======================================================================
72 // function : ~MeasureGUI()
73 // purpose  : Destructor
74 //=======================================================================
75 MeasureGUI::~MeasureGUI()
76 {
77 }
78
79
80 //=======================================================================
81 // function : OnGUIEvent()
82 // purpose  : 
83 //=======================================================================
84 bool MeasureGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
85 {
86   SalomeApp_Application* app = getGeometryGUI()->getApp();
87   if ( !app ) return false;
88
89   getGeometryGUI()->EmitSignalDeactivateDialog();
90
91   QDialog* dlg = 0;
92   switch ( theCommandID ) {
93   case GEOMOp::OpProperties:
94     dlg = new MeasureGUI_PropertiesDlg( getGeometryGUI(), parent );
95     break; // LENGTH, AREA AND VOLUME
96   case GEOMOp::OpCenterMass:
97     dlg = new MeasureGUI_CenterMassDlg( getGeometryGUI(), parent );
98     break; // CENTER MASS7
99   case GEOMOp::OpInertia:
100     dlg = new MeasureGUI_InertiaDlg( getGeometryGUI(), parent );
101     break; // INERTIA
102   case GEOMOp::OpNormale : 
103     dlg = new MeasureGUI_NormaleDlg( getGeometryGUI(), parent );
104     break; // NORMALE
105   case GEOMOp::OpBoundingBox:
106     dlg = new MeasureGUI_BndBoxDlg( getGeometryGUI(), parent );
107     break; // BOUNDING BOX
108   case GEOMOp::OpMinDistance:
109     dlg = new MeasureGUI_DistanceDlg( getGeometryGUI(), parent );
110     break; // MIN DISTANCE
111   case GEOMOp::OpAngle: 
112     dlg = new MeasureGUI_AngleDlg( getGeometryGUI(), parent );
113     break; // ANGLE
114   case GEOMOp::OpTolerance: 
115     dlg = new MeasureGUI_MaxToleranceDlg( getGeometryGUI(), parent );
116     break; // MAXTOLERANCE
117   case GEOMOp::OpWhatIs:
118     dlg = new MeasureGUI_WhatisDlg( getGeometryGUI(), parent );
119     break; // WHATIS
120   case GEOMOp::OpCheckShape:
121     dlg = new MeasureGUI_CheckShapeDlg( getGeometryGUI(), parent );
122     break; // CHECKSHAPE
123   case GEOMOp::OpCheckCompound:
124     dlg = new MeasureGUI_CheckCompoundOfBlocksDlg( getGeometryGUI(), parent );
125     break; // CHECKCOMPOUND
126   case GEOMOp::OpGetNonBlocks:
127     dlg = new MeasureGUI_GetNonBlocksDlg(getGeometryGUI(), parent);
128     break; // GET NON BLOCKS
129   case GEOMOp::OpCheckSelfInters:
130     dlg = new MeasureGUI_CheckSelfIntersectionsDlg( getGeometryGUI(), parent );
131     break; // CHECK SELF INTERSCTIONS
132   case GEOMOp::OpFastCheckInters:
133     dlg = new MeasureGUI_FastCheckIntersectionsDlg( getGeometryGUI(), parent );
134     break; // FAST CHECK INTERSCTIONS
135 #ifndef DISABLE_PLOT2DVIEWER
136   case GEOMOp::OpShapeStatistics:
137     dlg = new MeasureGUI_ShapeStatisticsDlg( parent );
138     break; // SHAPE STATISTICS
139 #endif
140   case GEOMOp::OpPointCoordinates:
141     dlg = new MeasureGUI_PointDlg( getGeometryGUI(), parent );
142     break; // POINT COORDINATES
143   case GEOMOp::OpManageDimensions:
144     if( !myManageDimensionDlg ) {
145       dlg = new MeasureGUI_ManageDimensionsDlg( getGeometryGUI(), parent );
146       myManageDimensionDlg = dlg;
147       connect( dlg, SIGNAL( finished(int) ), this, SLOT( onFinished(int) ) );
148     }
149     myManageDimensionDlg->activateWindow();
150     break; // MANAGE DIMENSIONS
151   case GEOMOp::OpShowAllDimensions:
152     ChangeDimensionsVisibility( true );
153     break; // SHOW ALL DIMENSIONS
154   case GEOMOp::OpHideAllDimensions:
155     ChangeDimensionsVisibility( false );
156     break; // HIDE ALL DIMENSIONS
157   default: 
158     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); 
159     break;
160   }
161   if ( dlg ) {
162     dlg->updateGeometry();
163     dlg->resize( dlg->minimumSizeHint() );
164     dlg->show();
165   }
166   return true;
167 }
168
169 //=======================================================================
170 // function : ChangeDimensionsVisibility
171 // purpose  : 
172 //=======================================================================
173 void MeasureGUI::ChangeDimensionsVisibility( const bool theIsVisible )
174 {
175   SalomeApp_Application* anApp = getGeometryGUI()->getApp();
176   if (!anApp)
177   {
178     return;
179   }
180
181   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
182   if ( !anActiveStudy )
183   {
184     return;
185   }
186
187   LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
188   if ( !aSelMgr )
189   {
190     return;
191   }
192
193   SALOME_ListIO aListIO;
194   aSelMgr->selectedObjects( aListIO );
195   if ( aListIO.Extent() != 1 )
196   {
197     return;
198   }
199
200   Handle(SALOME_InteractiveObject) anIObject = aListIO.First();
201   if ( !anIObject->hasEntry() )
202   {
203     return;
204   }
205
206   SUIT_OverrideCursor wc;
207
208   GEOMGUI_DimensionProperty aDimensions( anActiveStudy, anIObject->getEntry() );
209
210   for ( int anIt = 0; anIt < aDimensions.GetNumber(); ++anIt )
211   {
212     aDimensions.SetVisible( anIt, theIsVisible );
213   }
214
215   aDimensions.SaveToAttribute( anActiveStudy, anIObject->getEntry() );
216
217   GEOM_Displayer( anActiveStudy ).Redisplay( anIObject, true );
218 }
219
220 //=======================================================================
221 // function : onFinished
222 // purpose  : called then "Manage Dimension" dialog is closed.
223 //=======================================================================
224 void MeasureGUI::onFinished(int /*theResult*/) {
225   if(sender() == myManageDimensionDlg) {
226     myManageDimensionDlg = 0;
227   }
228 }
229
230 //=====================================================================================
231 // EXPORTED METHODS
232 //=====================================================================================
233 extern "C"
234 {
235 #ifdef WIN32
236   __declspec( dllexport )
237 #endif
238   GEOMGUI* GetLibGUI( GeometryGUI* parent )
239   {
240     return new MeasureGUI( parent );
241   }
242 }