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