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