]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Information.cxx
Salome HOME
115461bb8959ccc15d764af259f9944f94ae7aa8
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Information.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 //  SUPERV SUPERVGUI : GUI for Supervisor component
23 //  File   : SUPERVGUI_Information.cxx
24 //  Author : Francis KLOSS
25 //  Module : SUPERV
26 //
27 #include "SUPERVGUI_Information.h"
28 #include "SUPERVGUI.h"
29
30 #include "CAM_Application.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33
34 #include <qapplication.h>
35 #include <qlabel.h>
36 #include <qgroupbox.h>
37 #include <qlayout.h>
38
39 /*!
40   Constructor
41 */
42 SUPERVGUI_Information::SUPERVGUI_Information(SUPERV_CNode node, bool isReadOnly)
43      : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
44 {
45   Trace("SUPERVGUI_Information::SUPERVGUI_Information");
46   setCaption( tr( "TLT_INFORMATIONS" ) );
47   setSizeGripEnabled( true );
48   myNode = node;
49
50   QGridLayout* TopLayout = new QGridLayout( this );
51   TopLayout->setSpacing( 6 );
52   TopLayout->setMargin( 11 );
53     
54   QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
55   TopGroup->setColumnLayout(0, Qt::Vertical );
56   TopGroup->layout()->setSpacing( 0 );
57   TopGroup->layout()->setMargin( 0 );
58   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
59   TopGroupLayout->setAlignment( Qt::AlignTop );
60   TopGroupLayout->setSpacing( 6 );
61   TopGroupLayout->setMargin( 11 );
62
63   QLabel* nameL = new QLabel( tr( "NAME_LBL" ), TopGroup );  
64   nameV = new QLineEdit( TopGroup );      
65   nameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
66   nameV->setMinimumSize( 200, 0 );
67   nameV->setReadOnly( isReadOnly );
68   nameV->setText( node->Name() );
69   
70   QLabel* authL = new QLabel( tr( "AUTHOR_LBL" ), TopGroup); 
71   authV = new QLineEdit( TopGroup );
72   authV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
73   authV->setMinimumSize( 200, 0 );
74   authV->setReadOnly( isReadOnly );
75   authV->setText( node->Author() );
76
77   
78   if (node->IsFactory()) {
79     contL = new QLabel( tr( "CONTAINER_LBL" ), TopGroup ); 
80     contV = new QLineEdit( TopGroup );
81     contV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
82     contV->setMinimumSize( 200, 0 );
83     contV->setReadOnly( false/*isReadOnly*/ );
84     contV->setText( SUPERV::FNode::_narrow(node)->GetContainer() );
85
86     compnameL = new QLabel( tr( "COMPONENT_NAME_LBL" ), TopGroup ); 
87     compnameV = new QLineEdit( TopGroup );      
88     compnameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89     compnameV->setMinimumSize( 200, 0 );
90     compnameV->setReadOnly( true/*isReadOnly*/ );
91     compnameV->setText( SUPERV::FNode::_narrow(node)->GetComponentName() ); // mkr : IPAL10198
92
93     intnameL = new QLabel( tr( "INTERFACE_NAME_LBL" ), TopGroup ); 
94     intnameV = new QLineEdit( TopGroup );      
95     intnameV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96     intnameV->setMinimumSize( 200, 0 );
97     intnameV->setReadOnly( true/*isReadOnly*/ );
98     intnameV->setText( SUPERV::FNode::_narrow(node)->GetInterfaceName() );
99
100   }
101   QLabel* cdatL = new QLabel( tr( "DATE_CREATION_LBL" ), TopGroup ); 
102   cdatV = new QLabel( TopGroup );
103   cdatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
104   cdatV->setMinimumSize( 200, 0 );
105   cdatV->setText( date( node->CreationDate() ) );
106
107   QLabel* udatL = new QLabel( tr( "DATE_MODIFICATION_LBL" ), TopGroup ); 
108   udatV = new QLabel( TopGroup );
109   udatV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
110   udatV->setMinimumSize( 200, 0 );
111   udatV->setText( date( node->LastUpdateDate() ) );
112
113   QLabel* commL = new QLabel( tr( "COMMENT_LBL" ), TopGroup); 
114   commV = new QMultiLineEdit( TopGroup );
115   commV->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
116   commV->setMinimumSize( 200, 100 );
117   commV->setReadOnly( isReadOnly );
118   commV->setText( node->Comment() );
119
120   TopGroupLayout->addWidget( nameL, 0, 0 );
121   TopGroupLayout->addWidget( nameV, 0, 1 );
122   TopGroupLayout->addWidget( authL, 1, 0 );
123   TopGroupLayout->addWidget( authV, 1, 1 );
124   if (node->IsFactory()) {
125     TopGroupLayout->addWidget( contL, 2, 0 );
126     TopGroupLayout->addWidget( contV, 2, 1 );
127     TopGroupLayout->addWidget( compnameL, 3, 0 );
128     TopGroupLayout->addWidget( compnameV, 3, 1 );
129     TopGroupLayout->addWidget( intnameL, 4, 0 );
130     TopGroupLayout->addWidget( intnameV, 4, 1 );
131   }
132   TopGroupLayout->addWidget( cdatL, 5, 0 );
133   TopGroupLayout->addWidget( cdatV, 5, 1 );
134   TopGroupLayout->addWidget( udatL, 6, 0 );
135   TopGroupLayout->addWidget( udatV, 6, 1 );
136   TopGroupLayout->addWidget( commL, 7, 0 );
137   TopGroupLayout->addMultiCellWidget( commV, 7, 8, 1, 1 );
138   TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding  ), 8, 0 );
139   TopGroupLayout->setColStretch( 1, 5 );
140
141   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
142   GroupButtons->setColumnLayout(0, Qt::Vertical );
143   GroupButtons->layout()->setSpacing( 0 );
144   GroupButtons->layout()->setMargin( 0 );
145   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
146   GroupButtonsLayout->setAlignment( Qt::AlignTop );
147   GroupButtonsLayout->setSpacing( 6 );
148   GroupButtonsLayout->setMargin( 11 );
149
150   // fix for PAL6904: when isReadOnly is set ON (the dataflow was imported) then only "CLOSE" button
151   // should be present instead of 2 buttons OK and Cancel.
152   QPushButton* cancelB;
153   if ( !isReadOnly || node->IsFactory() )  {
154     /*added node->IsFactory() because only for Factory nodes we ALWAYS have editable "Container" field  */
155     QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
156     connect( okB,     SIGNAL( clicked() ), this, SLOT( okButton() ) );
157     cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
158     GroupButtonsLayout->addWidget( okB, 0, 0 );
159     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
160     GroupButtonsLayout->addWidget( cancelB, 0, 2 );
161   }
162   else {
163     cancelB = new QPushButton( tr( "BUT_CLOSE" ), GroupButtons );
164     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 0 );
165     GroupButtonsLayout->addWidget( cancelB, 0, 1 );
166     GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
167   }
168
169   TopLayout->addWidget( TopGroup,     0, 0 );
170   TopLayout->addWidget( GroupButtons, 1, 0 );
171   TopLayout->setRowStretch( 0, 1 );
172   TopLayout->setRowStretch( 1, 0 );
173
174   connect( cancelB, SIGNAL( clicked() ), this, SLOT( koButton() ) );
175 }
176
177 /*!
178   Destructor
179 */
180 SUPERVGUI_Information::~SUPERVGUI_Information() {
181   Trace("SUPERVGUI_Information::~SUPERVGUI_Information");
182 }
183
184 /*!
185   Executes dialog
186 */
187 /*
188 bool SUPERVGUI_Information::run( SUPERV_CNode node, bool isReadOnly ) {
189   Trace("SUPERVGUI_Information::run");
190   nameV->setReadOnly( isReadOnly );
191   authV->setReadOnly( isReadOnly );
192   commV->setReadOnly( isReadOnly );
193
194   nameV->setText( node->Name() );
195   authV->setText( node->Author() );
196   commV->setText( node->Comment() );
197   if (node->IsFactory()) {
198     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
199     contV->setText( aFNode->GetContainer());
200     contL->show();
201     contV->show();
202   }
203   else {
204     contL->hide();
205     contV->hide();
206   }
207   qApp->processEvents();
208   adjustSize();
209
210   //commV->setText( node->Comment() );
211   cdatV->setText( date( node->CreationDate() ) );
212   udatV->setText( date( node->LastUpdateDate() ) );
213
214   bool b1     = true;
215   bool b2     = true;
216   bool b3     = true;
217   bool b4     = true;
218   bool result = false;
219   if ( exec() == Accepted ) {
220     if (! isReadOnly ) {
221       //b3 = node->SetContainer( contV->text().latin1() );
222       //} 
223       //else {
224       if ( strcmp( node->Name(), nameV->text().latin1() ) != 0 ) {
225         b1 = node->SetName( nameV->text().latin1() );
226       }
227       b2 = node->SetAuthor   ( authV->text().latin1() );
228       if (node->IsFactory()) {
229         SUPERV_FNode aFNode = SUPERV::FNode::_narrow(node);
230         b3 = aFNode->SetContainer( contV->text().latin1() );
231       }
232       b4 = node->SetComment  ( commV->text().latin1() );
233     }
234     result = b1 && b2 && b3 && b4;
235     if ( !result ) {
236       QAD_MessageBox::warn1( this, tr( "ERROR" ), tr( "MSG_CANT_CHANGE_INFO" ), tr( "BUT_OK" ) );
237     }
238   }
239   return result;
240   }*/
241
242 /*!
243   Returns string representation of date
244 */
245 QString SUPERVGUI_Information::date( SUPERV_Date d ) {
246   Trace("SUPERVGUI_Information::date");
247   QString dt( "" );
248
249   if ( d.Day != 0 ) {
250     dt += ( char )( d.Day / 10 + 48 );
251     dt += ( char )( d.Day % 10 + 48 );
252     dt += '/';
253     dt += ( char )( d.Month / 10 + 48 );
254     dt += ( char )( d.Month % 10 + 48 );
255     dt += '/';
256     dt += ( char )( ( d.Year / 1000 ) %10 + 48 );
257     dt += ( char )( ( d.Year / 100 ) % 10 + 48 );
258     dt += ( char )( ( d.Year / 10  ) % 10 + 48 );
259     dt += ( char )( d.Year %10 + 48 );
260     dt += ' ';
261     dt += ( char )( d.Hour / 10 + 48 );
262     dt += ( char )( d.Hour % 10 + 48 );
263     dt += ':';
264     dt += ( char )( d.Minute / 10 + 48 );
265     dt += ( char )( d.Minute % 10 + 48 );
266     dt += ':';
267     dt += ( char )( d.Second / 10 + 48 );
268     dt += ( char )( d.Second % 10 + 48 );
269   };
270   return( dt );
271 }
272
273 /*!
274   <OK> button slot
275 */
276 void SUPERVGUI_Information::okButton() {
277   Trace("SUPERVGUI_Information::okButton");
278   //mkr : modifications for fixing bug IPAL9972
279   bool aIsAccept = true;
280   if ( QString( myNode->Name() ).compare( nameV->text() ) != 0 ) {
281     if ( !myNode->SetName( nameV->text().latin1()) ) {
282       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
283       aIsAccept = false;
284     }
285     // mkr : PAL7037 => update dataflow name in object browser if this dialog called for the dataflow and the dataflow is in study -->
286     if ( myNode->IsGraph() || myNode->IsStreamGraph() ) {
287       SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
288       if ( aSupMod ) aSupMod->updateDataFlowSOName(SUPERV::Graph::_narrow(myNode));
289     }
290     // mkr : PAL7037 <--
291   }
292   myNode->SetAuthor( authV->text().latin1() );
293   if (myNode->IsFactory()) {
294     SUPERV_FNode aFNode = SUPERV::FNode::_narrow(myNode);
295     aFNode->SetContainer( contV->text().latin1() );
296   }
297   myNode->SetComment( commV->text().latin1() );
298   if ( aIsAccept ) accept();
299 }
300
301 /*!
302   <Cancel> button slot
303 */
304 void SUPERVGUI_Information::koButton() {
305   Trace("SUPERVGUI_Information::koButton");
306   reject();
307 }