Salome HOME
7600f7313c32e02d6a5ac62c0f83817ed291a7ed
[modules/geom.git] / src / GEOMGUI / GEOMGUI_CreationInfoWdg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : GEOMGUI_CreationInfoWdg.cxx
20 // Created   : Fri Jun  7 13:07:59 2013
21 // Author    : Edward AGAPOV (eap)
22
23 #include "GEOMGUI_CreationInfoWdg.h"
24  
25 #include "GEOMImpl_Types.hxx"
26
27 #include <SUIT_Desktop.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31
32 #include <QString>
33 #include <QLabel>
34 #include <QLineEdit>
35 #include <QTreeWidget>
36 #include <QHeaderView>
37 #include <QGroupBox>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
40
41 GEOMGUI_CreationInfoWdg::GEOMGUI_CreationInfoWdg( SalomeApp_Application* app )
42 //:QWidget( app->desktop() )
43 {
44   setWindowTitle( tr( "CREATION_INFO_TITLE" ) );
45
46   myParamsTreeWd = new QTreeWidget( this );
47   myParamsTreeWd->setColumnCount( 2 );
48   myParamsTreeWd->setHeaderLabels( QStringList() << tr( "PARAMETER" ) << tr( "VALUE" ) );
49   myParamsTreeWd->header()->setStretchLastSection( true );
50   myParamsTreeWd->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );
51
52   QVBoxLayout* aLayout = new QVBoxLayout( this );
53   aLayout->addWidget( myParamsTreeWd );
54   aLayout->setMargin(11);
55
56   // get a free dockable window id
57   myWindowID = 10;
58   while( app->dockWindow( myWindowID ))
59     ++myWindowID;
60   ++myWindowID; // pb when a GEOM is a sole module: CreationInfoWdg replaces Python console
61 }
62
63 QTreeWidgetItem* GEOMGUI_CreationInfoWdg::addOperation(const QPixmap& icon, const QString& name)
64 {
65   QTreeWidgetItem* item = new QTreeWidgetItem( myParamsTreeWd );
66
67   item->setIcon( 0, icon );
68   item->setText( 0, name );
69   if ( name.isEmpty() )
70     item->setText( 0, tr("NO_INFO"));
71
72   item->setExpanded( true );
73
74   return item;
75 }
76
77 void GEOMGUI_CreationInfoWdg::addParam (QTreeWidgetItem* operation,
78                                         const QString&   name,
79                                         const QString&   value)
80 {
81   QTreeWidgetItem* item = new QTreeWidgetItem( operation );
82
83   //item->setFlags( Qt::NoItemFlags );
84   item->setExpanded( true );
85
86   item->setText( 0, name );
87   item->setText( 1, value );
88 }
89
90 void GEOMGUI_CreationInfoWdg::clear()
91 {
92   myParamsTreeWd->clear();
93 }
94
95 GEOMGUI_CreationInfoWdg::~GEOMGUI_CreationInfoWdg()
96 {
97   //std::cout<<"~GEOMGUI_CreationInfoWdg"<<std::endl;
98 }
99
100 void GEOMGUI_CreationInfoWdg::setInfo( GEOM::CreationInformationSeq& info )
101 {
102   clear();
103
104   QPixmap icon;
105   QString operationName;
106
107   try
108   {
109     if ( info.length() > 0 )
110     {
111       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
112       for ( int j = 0, nb = info.length(); j < nb; ++j )
113       {
114         QString name = info[j].operationName.in();
115         if ( !name.isEmpty() )
116         {
117           // get plugin_name if any
118           QString plugin_name;
119           for ( size_t i = 0; i < info[j].params.length(); ++i )
120           {
121             QString value = info[j].params[i].name.in();
122             if ( value == PLUGIN_NAME )
123               plugin_name = info[j].params[i].value.in();
124           }
125           // get icon
126           QString prefix = plugin_name.isEmpty() ? "GEOM" : plugin_name;
127           if ( name.startsWith( "Import"))
128             icon = resMgr->loadPixmap( "GEOM", tr("ICO_IMPORT_SHAPE"), true );
129           else
130             icon = resMgr->loadPixmap( prefix, tr( ("ICO_"+name).toLatin1().constData() ), false );
131
132           // translate operation name
133           operationName = tr( ("MEN_"+name).toLatin1().constData() );
134           if ( operationName.startsWith( "MEN_" ))
135             operationName = name; // no translation
136
137           QTreeWidgetItem* operation = addOperation( icon, operationName );
138
139           // add parameters
140           for ( size_t i = 0; i < info[j].params.length(); ++i )
141             addParam( operation,
142                       info[j].params[i].name.in(),
143                       info[j].params[i].value.in() );
144         }
145       }
146     }
147     else
148     {
149       addOperation( icon, operationName );
150     }
151   }
152   catch (...)
153   {
154   }
155 }