1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : GEOMGUI_CreationInfoWdg.cxx
20 // Created : Fri Jun 7 13:07:59 2013
21 // Author : Edward AGAPOV (eap)
23 #include "GEOMGUI_CreationInfoWdg.h"
25 #include "GEOMImpl_Types.hxx"
27 #include <SUIT_Desktop.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
35 #include <QTreeWidget>
36 #include <QHeaderView>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
41 GEOMGUI_CreationInfoWdg::GEOMGUI_CreationInfoWdg( SalomeApp_Application* app )
42 //:QWidget( app->desktop() )
44 setWindowTitle( tr( "CREATION_INFO_TITLE" ) );
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 );
53 myParamsTreeWd->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );
56 QVBoxLayout* aLayout = new QVBoxLayout( this );
57 aLayout->addWidget( myParamsTreeWd );
58 aLayout->setMargin(11);
60 // get a free dockable window id
62 while( app->dockWindow( myWindowID ))
64 ++myWindowID; // pb when a GEOM is a sole module: CreationInfoWdg replaces Python console
67 QTreeWidgetItem* GEOMGUI_CreationInfoWdg::addOperation(const QPixmap& icon, const QString& name)
69 QTreeWidgetItem* item = new QTreeWidgetItem( myParamsTreeWd );
71 item->setIcon( 0, icon );
72 item->setText( 0, name );
74 item->setText( 0, tr("NO_INFO"));
76 item->setExpanded( true );
81 void GEOMGUI_CreationInfoWdg::addParam (QTreeWidgetItem* operation,
85 QTreeWidgetItem* item = new QTreeWidgetItem( operation );
87 //item->setFlags( Qt::NoItemFlags );
88 item->setExpanded( true );
90 item->setText( 0, name );
91 item->setText( 1, value );
94 void GEOMGUI_CreationInfoWdg::clear()
96 myParamsTreeWd->clear();
99 GEOMGUI_CreationInfoWdg::~GEOMGUI_CreationInfoWdg()
101 //std::cout<<"~GEOMGUI_CreationInfoWdg"<<std::endl;
104 void GEOMGUI_CreationInfoWdg::setInfo( GEOM::CreationInformationSeq& info )
109 QString operationName;
113 if ( &info && info.length() > 0 )
115 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
116 for ( int j = 0, nb = info.length(); j < nb; ++j )
118 QString name = info[j].operationName.in();
119 if ( !name.isEmpty() )
121 // get plugin_name if any
123 for ( size_t i = 0; i < info[j].params.length(); ++i )
125 QString value = info[j].params[i].name.in();
126 if ( value == PLUGIN_NAME )
127 plugin_name = info[j].params[i].value.in();
130 QString prefix = plugin_name.isEmpty() ? "GEOM" : plugin_name;
131 if ( name.startsWith( "Import"))
132 icon = resMgr->loadPixmap( "GEOM", tr("ICO_IMPORT_SHAPE"), true );
134 icon = resMgr->loadPixmap( prefix, tr( ("ICO_"+name).toLatin1().constData() ), false );
136 // translate operation name
137 operationName = tr( ("MEN_"+name).toLatin1().constData() );
138 if ( operationName.startsWith( "MEN_" ))
139 operationName = name; // no translation
141 QTreeWidgetItem* operation = addOperation( icon, operationName );
144 for ( size_t i = 0; i < info[j].params.length(); ++i )
146 info[j].params[i].name.in(),
147 info[j].params[i].value.in() );
153 addOperation( icon, operationName );