Salome HOME
Merge branch V7_3_1_BR
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CheckShapeDlg.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_CheckShapeDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 //
27 #include "MeasureGUI_CheckShapeDlg.h"
28 #include "MeasureGUI_Widgets.h"
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Tools.h>
33
34 #define TEXTEDIT_FONT_FAMILY "Courier"
35 #define TEXTEDIT_FONT_SIZE 11
36
37 //=================================================================================
38 // class    : MeasureGUI_CheckShapeDlg()
39 // purpose  : Constructs a MeasureGUI_CheckShapeDlg which is a child of 'parent', with the
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            true to construct a modal dialog.
43 //=================================================================================
44 MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* parent )
45   : MeasureGUI_Skeleton( GUI, parent )
46 {
47   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
48     "GEOM", tr( "ICON_DLG_CHECKSHAPE" ) ) );
49   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
50     "GEOM", tr( "ICON_SELECT" ) ) );
51
52   setWindowTitle( tr( "GEOM_CHECK_TITLE" ) );
53
54   /***************************************************************/
55
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58
59   myGrp = new MeasureGUI_1Sel1TextView1Check( centralWidget() );
60   myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
61   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
62   myGrp->TextView1->setReadOnly( true );
63
64   QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
65   aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
66   myGrp->TextView1->setFont( aFont );
67   myGrp->PushButton1->setIcon( image1 );
68   myGrp->LineEdit1->setReadOnly( true );
69
70   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71   layout->setMargin( 0 ); layout->setSpacing( 6 );
72   layout->addWidget( myGrp );
73
74   /***************************************************************/
75
76   myHelpFileName = "using_measurement_tools_page.html#check_anchor";
77
78   /* Initialisation */
79   Init();
80 }
81
82 //=================================================================================
83 // function : ~MeasureGUI_CheckShapeDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg()
87 {
88 }
89
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void MeasureGUI_CheckShapeDlg::Init()
96 {
97   mySelBtn = myGrp->PushButton1;
98   mySelEdit = myGrp->LineEdit1;
99   MeasureGUI_Skeleton::Init();
100
101   connect( myGrp->CheckBox1, SIGNAL( toggled( bool) ), 
102            this, SLOT( SelectionIntoArgument() ) );
103 }
104
105 //=================================================================================
106 // function : getParameters
107 // purpose  :
108 //=================================================================================
109 bool MeasureGUI_CheckShapeDlg::getParameters ( bool& theIsValid, QString& theMsg )
110 {
111   if ( myObj->_is_nil() )
112     return false;
113   else {
114     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
115     try {
116       char* aMsg;
117       bool isCheckGeometry = myGrp->CheckBox1->isChecked();
118       if ( isCheckGeometry )
119         theIsValid = anOper->CheckShapeWithGeometry( myObj, aMsg );
120       else
121         theIsValid = anOper->CheckShape( myObj, aMsg );
122       theMsg = aMsg;
123     }
124     catch( const SALOME::SALOME_Exception& e ) {
125       SalomeApp_Tools::QtCatchCorbaException( e );
126       return false;
127     }
128
129     return anOper->IsDone();
130   }
131 }
132
133
134 //=================================================================================
135 // function : processObject
136 // purpose  :
137 //=================================================================================
138 void MeasureGUI_CheckShapeDlg::processObject()
139 {
140   bool isShapeValid;
141   QString aMsg;
142   if ( !getParameters( isShapeValid, aMsg ) ) {
143     myGrp->TextView1->setText( "" );
144     return;
145   }
146
147   if ( isShapeValid ) {
148     myGrp->TextView1->setText( "This Shape seems to be valid." );
149   } 
150   else {
151     QString aDescr ( "This Shape is not valid.\n" );
152     aDescr += aMsg;
153     myGrp->TextView1->setText( aDescr );
154 //    myGrp->TextView1->setText("This Shape is not valid.");
155   }
156 }