Salome HOME
Patch for MacOS (from SALOME forum)
[modules/geom.git] / src / GEOMGUI / GEOMGUI_CreationInfoWdg.cxx
1 // Copyright (C) 2007-2016  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 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
51   myParamsTreeWd->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
52 #else
53   myParamsTreeWd->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );
54 #endif
55
56   QVBoxLayout* aLayout = new QVBoxLayout( this );
57   aLayout->addWidget( myParamsTreeWd );
58   aLayout->setMargin(11);
59
60   // get a free dockable window id
61   myWindowID = 10;
62   while( app->dockWindow( myWindowID ))
63     ++myWindowID;
64   ++myWindowID; // pb when a GEOM is a sole module: CreationInfoWdg replaces Python console
65 }
66
67 QTreeWidgetItem* GEOMGUI_CreationInfoWdg::addOperation(const QPixmap& icon, const QString& name)
68 {
69   QTreeWidgetItem* item = new QTreeWidgetItem( myParamsTreeWd );
70
71   item->setIcon( 0, icon );
72   item->setText( 0, name );
73   if ( name.isEmpty() )
74     item->setText( 0, tr("NO_INFO"));
75
76   item->setExpanded( true );
77
78   return item;
79 }
80
81 void GEOMGUI_CreationInfoWdg::addParam (QTreeWidgetItem* operation,
82                                         const QString&   name,
83                                         const QString&   value)
84 {
85   QTreeWidgetItem* item = new QTreeWidgetItem( operation );
86
87   //item->setFlags( Qt::NoItemFlags );
88   item->setExpanded( true );
89
90   item->setText( 0, name );
91   item->setText( 1, value );
92 }
93
94 void GEOMGUI_CreationInfoWdg::clear()
95 {
96   myParamsTreeWd->clear();
97 }
98
99 GEOMGUI_CreationInfoWdg::~GEOMGUI_CreationInfoWdg()
100 {
101   //std::cout<<"~GEOMGUI_CreationInfoWdg"<<std::endl;
102 }
103
104 void GEOMGUI_CreationInfoWdg::setInfo( GEOM::CreationInformationSeq& info )
105 {
106   clear();
107
108   QPixmap icon;
109   QString operationName;
110
111   try
112   {
113     if ( &info && info.length() > 0 )
114     {
115       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116       for ( int j = 0, nb = info.length(); j < nb; ++j )
117       {
118         QString name = info[j].operationName.in();
119         if ( !name.isEmpty() )
120         {
121           // get plugin_name if any
122           QString plugin_name;
123           for ( size_t i = 0; i < info[j].params.length(); ++i )
124           {
125             QString value = info[j].params[i].name.in();
126             if ( value == PLUGIN_NAME )
127               plugin_name = info[j].params[i].value.in();
128           }
129           // get icon
130           QString prefix = plugin_name.isEmpty() ? "GEOM" : plugin_name;
131           if ( name.startsWith( "Import"))
132             icon = resMgr->loadPixmap( "GEOM", tr("ICO_IMPORT_SHAPE"), true );
133           else
134             icon = resMgr->loadPixmap( prefix, tr( ("ICO_"+name).toLatin1().constData() ), false );
135
136           // translate operation name
137           operationName = tr( ("MEN_"+name).toLatin1().constData() );
138           if ( operationName.startsWith( "MEN_" ))
139             operationName = name; // no translation
140
141           QTreeWidgetItem* operation = addOperation( icon, operationName );
142
143           // add parameters
144           for ( size_t i = 0; i < info[j].params.length(); ++i )
145             addParam( operation,
146                       info[j].params[i].name.in(),
147                       info[j].params[i].value.in() );
148         }
149       }
150     }
151     else
152     {
153       addOperation( icon, operationName );
154     }
155   }
156   catch (...)
157   {
158   }
159 }