Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CheckShapeDlg.cxx
1 //  Copyright (C) 2007-2008  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : MeasureGUI_CheckShapeDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 //
26 #include "MeasureGUI_CheckShapeDlg.h"
27 #include "MeasureGUI_Widgets.h"
28
29 #include <SUIT_Session.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Tools.h>
32
33 #define TEXTEDIT_FONT_FAMILY "Courier"
34 #define TEXTEDIT_FONT_SIZE 11
35
36 //=================================================================================
37 // class    : MeasureGUI_CheckShapeDlg()
38 // purpose  : Constructs a MeasureGUI_CheckShapeDlg which is a child of 'parent', with the
39 //            name 'name' and widget flags set to 'f'.
40 //            The dialog will by default be modeless, unless you set 'modal' to
41 //            true to construct a modal dialog.
42 //=================================================================================
43 MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* parent )
44   : MeasureGUI_Skeleton( GUI, parent )
45 {
46   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
47     "GEOM", tr( "ICON_DLG_CHECKSHAPE" ) ) );
48   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
49     "GEOM", tr( "ICON_SELECT" ) ) );
50
51   setWindowTitle( tr( "GEOM_CHECK_TITLE" ) );
52
53   /***************************************************************/
54
55   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
56   mainFrame()->RadioButton1->setIcon( image0 );
57
58   myGrp = new MeasureGUI_1Sel1TextView1Check( centralWidget() );
59   myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
60   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
61   myGrp->TextView1->setReadOnly( true );
62
63   QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
64   aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
65   myGrp->TextView1->setFont( aFont );
66   myGrp->PushButton1->setIcon( image1 );
67   myGrp->LineEdit1->setReadOnly( true );
68
69   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
70   layout->setMargin( 0 ); layout->setSpacing( 6 );
71   layout->addWidget( myGrp );
72
73   /***************************************************************/
74
75   myHelpFileName = "using_measurement_tools_page.html#check_anchor";
76
77   /* Initialisation */
78   Init();
79 }
80
81 //=================================================================================
82 // function : ~MeasureGUI_CheckShapeDlg()
83 // purpose  : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg()
86 {
87 }
88
89
90 //=================================================================================
91 // function : Init()
92 // purpose  :
93 //=================================================================================
94 void MeasureGUI_CheckShapeDlg::Init()
95 {
96   mySelBtn = myGrp->PushButton1;
97   mySelEdit = myGrp->LineEdit1;
98   MeasureGUI_Skeleton::Init();
99
100   connect( myGrp->CheckBox1, SIGNAL( toggled( bool) ), 
101            this, SLOT( SelectionIntoArgument() ) );
102 }
103
104 //=================================================================================
105 // function : getParameters
106 // purpose  :
107 //=================================================================================
108 bool MeasureGUI_CheckShapeDlg::getParameters ( bool& theIsValid, QString& theMsg )
109 {
110   if ( myObj->_is_nil() )
111     return false;
112   else {
113     try {
114       char* aMsg;
115       bool isCheckGeometry = myGrp->CheckBox1->isChecked();
116       GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
117         GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
118       if ( isCheckGeometry )
119         theIsValid = aMeasureOp->CheckShapeWithGeometry( myObj, aMsg );
120       else
121         theIsValid = aMeasureOp->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 getOperation()->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 }