Salome HOME
Synchronize adm files
[modules/geom.git] / src / MeasureGUI / MeasureGUI.cxx
1 // Copyright (C) 2007-2014  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_PointDlg.h"                  // Method POINTCOORDINATES
54 #include "MeasureGUI_ManageDimensionsDlg.h"       // Method MANAGEDIMENSIONS
55
56 #include <QApplication>
57
58 //=======================================================================
59 // function : MeasureGUI()
60 // purpose  : Constructor
61 //=======================================================================
62 MeasureGUI::MeasureGUI( GeometryGUI* parent ) : GEOMGUI( parent )
63 {
64   myManageDimensionDlg = 0;
65 }
66
67 //=======================================================================
68 // function : ~MeasureGUI()
69 // purpose  : Destructor
70 //=======================================================================
71 MeasureGUI::~MeasureGUI()
72 {
73 }
74
75
76 //=======================================================================
77 // function : OnGUIEvent()
78 // purpose  : 
79 //=======================================================================
80 bool MeasureGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
81 {
82   SalomeApp_Application* app = getGeometryGUI()->getApp();
83   if ( !app ) return false;
84
85   getGeometryGUI()->EmitSignalDeactivateDialog();
86
87   QDialog* dlg = 0;
88   switch ( theCommandID ) {
89   case GEOMOp::OpProperties:
90     dlg = new MeasureGUI_PropertiesDlg( getGeometryGUI(), parent );
91     break; // LENGTH, AREA AND VOLUME
92   case GEOMOp::OpCenterMass:
93     dlg = new MeasureGUI_CenterMassDlg( getGeometryGUI(), parent );
94     break; // CENTER MASS7
95   case GEOMOp::OpInertia:
96     dlg = new MeasureGUI_InertiaDlg( getGeometryGUI(), parent );
97     break; // INERTIA
98   case GEOMOp::OpNormale : 
99     dlg = new MeasureGUI_NormaleDlg( getGeometryGUI(), parent );
100     break; // NORMALE
101   case GEOMOp::OpBoundingBox:
102     dlg = new MeasureGUI_BndBoxDlg( getGeometryGUI(), parent );
103     break; // BOUNDING BOX
104   case GEOMOp::OpMinDistance:
105     dlg = new MeasureGUI_DistanceDlg( getGeometryGUI(), parent );
106     break; // MIN DISTANCE
107   case GEOMOp::OpAngle: 
108     dlg = new MeasureGUI_AngleDlg( getGeometryGUI(), parent );
109     break; // ANGLE
110   case GEOMOp::OpTolerance: 
111     dlg = new MeasureGUI_MaxToleranceDlg( getGeometryGUI(), parent );
112     break; // MAXTOLERANCE
113   case GEOMOp::OpWhatIs:
114     dlg = new MeasureGUI_WhatisDlg( getGeometryGUI(), parent );
115     break; // WHATIS
116   case GEOMOp::OpCheckShape:
117     dlg = new MeasureGUI_CheckShapeDlg( getGeometryGUI(), parent );
118     break; // CHECKSHAPE
119   case GEOMOp::OpCheckCompound:
120     dlg = new MeasureGUI_CheckCompoundOfBlocksDlg( getGeometryGUI(), parent );
121     break; // CHECKCOMPOUND
122   case GEOMOp::OpGetNonBlocks:
123     dlg = new MeasureGUI_GetNonBlocksDlg(getGeometryGUI(), parent);
124     break; // GET NON BLOCKS
125   case GEOMOp::OpCheckSelfInters:
126     dlg = new MeasureGUI_CheckSelfIntersectionsDlg( getGeometryGUI(), parent );
127     break; // CHECK SELF INTERSCTIONS
128   case GEOMOp::OpPointCoordinates:
129     dlg = new MeasureGUI_PointDlg( getGeometryGUI(), parent );
130     break; // POINT COORDINATES
131   case GEOMOp::OpManageDimensions:
132     if( !myManageDimensionDlg ) {
133       dlg = new MeasureGUI_ManageDimensionsDlg( getGeometryGUI(), parent );
134       myManageDimensionDlg = dlg;
135       connect( dlg, SIGNAL( finished(int) ), this, SLOT( onFinished(int) ) );
136     }
137     myManageDimensionDlg->activateWindow();
138     break; // MANAGE DIMENSIONS
139   case GEOMOp::OpShowAllDimensions:
140     ChangeDimensionsVisibility( true );
141     break; // SHOW ALL DIMENSIONS
142   case GEOMOp::OpHideAllDimensions:
143     ChangeDimensionsVisibility( false );
144     break; // HIDE ALL DIMENSIONS
145   default: 
146     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); 
147     break;
148   }
149   if ( dlg ) {
150     dlg->updateGeometry();
151     dlg->resize( dlg->minimumSizeHint() );
152     dlg->show();
153   }
154   return true;
155 }
156
157 //=======================================================================
158 // function : ChangeDimensionsVisibility
159 // purpose  : 
160 //=======================================================================
161 void MeasureGUI::ChangeDimensionsVisibility( const bool theIsVisible )
162 {
163   SalomeApp_Application* anApp = getGeometryGUI()->getApp();
164   if (!anApp)
165   {
166     return;
167   }
168
169   SalomeApp_Study* anActiveStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
170   if ( !anActiveStudy )
171   {
172     return;
173   }
174
175   LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr();
176   if ( !aSelMgr )
177   {
178     return;
179   }
180
181   SALOME_ListIO aListIO;
182   aSelMgr->selectedObjects( aListIO );
183   if ( aListIO.Extent() != 1 )
184   {
185     return;
186   }
187
188   Handle(SALOME_InteractiveObject) anIObject = aListIO.First();
189   if ( !anIObject->hasEntry() )
190   {
191     return;
192   }
193
194   SUIT_OverrideCursor();
195
196   GEOMGUI_DimensionProperty aDimensions( anActiveStudy, anIObject->getEntry() );
197
198   for ( int anIt = 0; anIt < aDimensions.GetNumber(); ++anIt )
199   {
200     aDimensions.SetVisible( anIt, theIsVisible );
201   }
202
203   aDimensions.SaveToAttribute( anActiveStudy, anIObject->getEntry() );
204
205   GEOM_Displayer( anActiveStudy ).Redisplay( anIObject, true );
206 }
207
208 //=======================================================================
209 // function : onFinished
210 // purpose  : called then "Manage Dimension" dialog is closed.
211 //=======================================================================
212 void MeasureGUI::onFinished(int /*theResult*/) {
213   if(sender() == myManageDimensionDlg) {
214     myManageDimensionDlg = 0;
215   }
216 }
217
218 //=====================================================================================
219 // EXPORTED METHODS
220 //=====================================================================================
221 extern "C"
222 {
223 #ifdef WIN32
224   __declspec( dllexport )
225 #endif
226   GEOMGUI* GetLibGUI( GeometryGUI* parent )
227   {
228     return new MeasureGUI( parent );
229   }
230 }