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