2004-06-18 14:34:31 +06:00
|
|
|
// SMESH SMESHGUI : GUI for SMESH component
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 CEA
|
2005-06-07 19:22:20 +06:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
2004-06-18 14:34:31 +06:00
|
|
|
// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// File : SMESHGUI_CreateHypothesesDlg.cxx
|
|
|
|
// Author : Julia DOROVSKIKH
|
|
|
|
// Module : SMESH
|
|
|
|
// $Header$
|
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
#include "SMESHGUI_CreateHypothesesDlg.h"
|
2005-06-07 19:22:20 +06:00
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
#include "SMESHGUI_HypothesesUtils.h"
|
|
|
|
#include "SMESHGUI_Hypotheses.h"
|
|
|
|
#include "SMESHGUI_Utils.h"
|
|
|
|
#include "SMESHGUI.h"
|
|
|
|
|
2005-06-07 19:22:20 +06:00
|
|
|
#include "SUIT_Desktop.h"
|
|
|
|
#include "SUIT_ResourceMgr.h"
|
|
|
|
|
|
|
|
#include "SALOME_ListIteratorOfListIO.hxx"
|
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
#include "utilities.h"
|
|
|
|
|
2005-06-07 19:22:20 +06:00
|
|
|
// QT Includes
|
|
|
|
#include <qbuttongroup.h>
|
|
|
|
#include <qgroupbox.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qlayout.h>
|
|
|
|
#include <qlistview.h>
|
|
|
|
#include <qheader.h>
|
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
using namespace std;
|
|
|
|
|
2004-06-18 14:34:31 +06:00
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
// function : SMESHGUI_CreateHypothesesDlg()
|
|
|
|
// purpose : Constructs a SMESHGUI_CreateHypothesesDlg which is a child of 'parent', with the
|
2004-06-18 14:34:31 +06:00
|
|
|
// name 'name' and widget flags set to 'f'.
|
|
|
|
// The dialog will by default be modeless, unless you set 'modal' to
|
|
|
|
// TRUE to construct a modal dialog.
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg (SMESHGUI* theModule,
|
2004-06-18 14:34:31 +06:00
|
|
|
const char* name,
|
|
|
|
bool modal,
|
|
|
|
bool isAlgo)
|
2005-06-07 19:22:20 +06:00
|
|
|
: QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
|
|
|
|
WStyle_Title | WStyle_SysMenu | WDestructiveClose),
|
|
|
|
myIsAlgo(isAlgo),
|
|
|
|
mySMESHGUI( theModule )
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
if (!name)
|
|
|
|
setName("SMESHGUI_CreateHypothesesDlg");
|
|
|
|
setCaption(isAlgo ? tr("SMESH_CREATE_ALGORITHMS" ) : tr("SMESH_CREATE_HYPOTHESES" ));
|
|
|
|
setSizeGripEnabled(TRUE);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
2005-06-07 19:22:20 +06:00
|
|
|
QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout(this);
|
|
|
|
SMESHGUI_CreateHypothesesDlgLayout->setSpacing(6);
|
|
|
|
SMESHGUI_CreateHypothesesDlgLayout->setMargin(11);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
|
|
|
/***************************************************************/
|
2005-06-07 19:22:20 +06:00
|
|
|
GroupAlgorithms = new QGroupBox(this, "GroupAlgorithms");
|
|
|
|
GroupAlgorithms->setTitle(isAlgo ? tr("SMESH_AVAILABLE_ALGORITHMS") : tr("SMESH_AVAILABLE_HYPOTHESES"));
|
|
|
|
GroupAlgorithms->setColumnLayout(0, Qt::Vertical);
|
|
|
|
GroupAlgorithms->layout()->setSpacing(0);
|
|
|
|
GroupAlgorithms->layout()->setMargin(0);
|
|
|
|
|
|
|
|
QGridLayout* hypLayout = new QGridLayout(GroupAlgorithms->layout());
|
|
|
|
hypLayout->setGeometry(QRect(12, 18, 139, 250));
|
|
|
|
hypLayout->setAlignment(Qt::AlignTop);
|
|
|
|
hypLayout->setSpacing(6);
|
|
|
|
hypLayout->setMargin(11);
|
|
|
|
|
|
|
|
ListAlgoDefinition = new QListView(GroupAlgorithms, "ListAlgoDefinition");
|
|
|
|
ListAlgoDefinition->setMinimumSize(400, 200);
|
2004-06-18 14:34:31 +06:00
|
|
|
ListAlgoDefinition->addColumn("");
|
|
|
|
ListAlgoDefinition->header()->hide();
|
|
|
|
ListAlgoDefinition->setSelectionMode(QListView::Single);
|
|
|
|
ListAlgoDefinition->setResizeMode(QListView::AllColumns);
|
2005-06-07 19:22:20 +06:00
|
|
|
ListAlgoDefinition->setRootIsDecorated(true);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
2005-06-07 19:22:20 +06:00
|
|
|
hypLayout->addWidget(ListAlgoDefinition, 0, 0);
|
|
|
|
SMESHGUI_CreateHypothesesDlgLayout->addWidget(GroupAlgorithms, 0, 0);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
|
|
|
/***************************************************************/
|
2005-06-07 19:22:20 +06:00
|
|
|
GroupButtons = new QGroupBox(this, "GroupButtons");
|
|
|
|
GroupButtons->setColumnLayout(0, Qt::Vertical);
|
|
|
|
GroupButtons->layout()->setSpacing(0);
|
|
|
|
GroupButtons->layout()->setMargin(0);
|
|
|
|
QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
|
|
|
|
GroupButtonsLayout->setAlignment(Qt::AlignTop);
|
|
|
|
GroupButtonsLayout->setSpacing(6);
|
|
|
|
GroupButtonsLayout->setMargin(11);
|
|
|
|
|
|
|
|
buttonApply = new QPushButton(GroupButtons, "buttonApply");
|
|
|
|
buttonApply->setText(tr("SMESH_BUT_CREATE" ));
|
|
|
|
buttonApply->setAutoDefault(TRUE);
|
|
|
|
buttonApply->setDefault(FALSE);
|
|
|
|
buttonApply->setEnabled(FALSE);
|
|
|
|
GroupButtonsLayout->addWidget(buttonApply, 0, 1);
|
|
|
|
|
|
|
|
QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
GroupButtonsLayout->addItem(spacer_9, 0, 2);
|
|
|
|
|
|
|
|
buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
|
|
|
|
buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
|
|
|
|
buttonCancel->setAutoDefault(TRUE);
|
|
|
|
buttonCancel->setDefault(TRUE);
|
|
|
|
buttonCancel->setEnabled(TRUE);
|
|
|
|
GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
|
|
|
|
|
|
|
|
SMESHGUI_CreateHypothesesDlgLayout->addWidget(GroupButtons, 1, 0);
|
2004-06-18 14:34:31 +06:00
|
|
|
/***************************************************************/
|
|
|
|
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ~SMESHGUI_CreateHypothesesDlg()
|
|
|
|
// purpose : Destroys the object and frees any allocated resources
|
|
|
|
//=================================================================================
|
|
|
|
SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
|
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
// no need to delete child widgets, Qt does it all for us
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : Init()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::Init()
|
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
mySMESHGUI->SetActiveDialogBox((QDialog*)this);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
|
|
|
InitAlgoDefinition();
|
|
|
|
|
|
|
|
/* signals and slots connections */
|
2005-06-07 19:22:20 +06:00
|
|
|
connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
|
|
|
|
connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
|
|
|
|
|
|
|
|
// connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
|
|
|
|
connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
|
|
|
|
|
|
|
|
connect(ListAlgoDefinition, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
|
|
|
|
connect(ListAlgoDefinition, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(onDoubleClicked(QListViewItem*)));
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
mySMESHGUI->DefineDlgPosition(this, x, y);
|
|
|
|
this->move(x, y);
|
|
|
|
this->show();
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnCancel()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::ClickOnCancel()
|
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
close();
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnApply()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::ClickOnApply()
|
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
if (mySMESHGUI->isActiveStudyLocked())
|
2004-12-01 15:48:31 +05:00
|
|
|
return;
|
2004-06-18 14:34:31 +06:00
|
|
|
QListViewItem* item = ListAlgoDefinition->selectedItem();
|
2005-06-07 19:22:20 +06:00
|
|
|
if (!item)
|
2004-06-18 14:34:31 +06:00
|
|
|
return;
|
2005-06-07 19:22:20 +06:00
|
|
|
QString aHypType = item->text(1);
|
2004-06-18 14:34:31 +06:00
|
|
|
MESSAGE("Apply " << aHypType);
|
|
|
|
char* sHypType = (char*)aHypType.latin1();
|
|
|
|
|
2004-12-01 15:48:31 +05:00
|
|
|
HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType);
|
2005-06-07 19:22:20 +06:00
|
|
|
if (!aHypData)
|
2004-06-18 14:34:31 +06:00
|
|
|
return;
|
|
|
|
QString aClientLibName = aHypData->ClientLibName;
|
|
|
|
MESSAGE("Client lib name = " << aClientLibName);
|
|
|
|
|
2005-06-07 19:22:20 +06:00
|
|
|
if (aClientLibName == "") {
|
2004-06-18 14:34:31 +06:00
|
|
|
// Call hypothesis creation server method (without GUI)
|
|
|
|
QString aHypName = aHypData->Label;
|
2004-12-01 15:48:31 +05:00
|
|
|
SMESH::CreateHypothesis(sHypType, aHypName, myIsAlgo);
|
2005-06-07 19:22:20 +06:00
|
|
|
} else {
|
2004-06-18 14:34:31 +06:00
|
|
|
// Get hypotheses creator client (GUI)
|
|
|
|
SMESHGUI_GenericHypothesisCreator* aCreator =
|
2004-12-01 15:48:31 +05:00
|
|
|
SMESH::GetHypothesisCreator(sHypType);
|
2004-06-18 14:34:31 +06:00
|
|
|
|
|
|
|
// Create hypothesis/algorithm
|
|
|
|
aCreator->CreateHypothesis(myIsAlgo, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// buttonApply->setEnabled(FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ActivateThisDialog()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::ActivateThisDialog()
|
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
mySMESHGUI->EmitSignalDeactivateDialog();
|
|
|
|
GroupButtons->setEnabled(true);
|
|
|
|
return;
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : enterEvent()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
void SMESHGUI_CreateHypothesesDlg::enterEvent (QEvent*)
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
ActivateThisDialog();
|
|
|
|
return;
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : closeEvent()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
void SMESHGUI_CreateHypothesesDlg::closeEvent (QCloseEvent* e)
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
|
|
|
mySMESHGUI->ResetState();
|
2005-06-07 19:22:20 +06:00
|
|
|
QDialog::closeEvent(e);
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : onSelectionChanged()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::onSelectionChanged()
|
|
|
|
{
|
|
|
|
QListViewItem* item = ListAlgoDefinition->selectedItem();
|
2005-06-07 19:22:20 +06:00
|
|
|
buttonApply->setEnabled(item && item->depth() > 0);
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : onDoubleClicked()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2005-06-07 19:22:20 +06:00
|
|
|
void SMESHGUI_CreateHypothesesDlg::onDoubleClicked (QListViewItem* i)
|
2004-06-18 14:34:31 +06:00
|
|
|
{
|
2005-06-07 19:22:20 +06:00
|
|
|
if (i && i->depth() > 0)
|
2004-06-18 14:34:31 +06:00
|
|
|
this->ClickOnApply();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : InitAlgoDefinition()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void SMESHGUI_CreateHypothesesDlg::InitAlgoDefinition()
|
|
|
|
{
|
|
|
|
ListAlgoDefinition->clear();
|
2004-12-01 15:48:31 +05:00
|
|
|
QStringList HypList = SMESH::GetAvailableHypotheses(myIsAlgo);
|
2005-06-07 19:22:20 +06:00
|
|
|
for (int i = 0; i < HypList.count(); ++i) {
|
|
|
|
HypothesisData* aHypData = SMESH::GetHypothesisData(HypList[i]);
|
2004-06-18 14:34:31 +06:00
|
|
|
QListViewItem* parentItem = 0;
|
|
|
|
QListViewItem* childItem = ListAlgoDefinition->firstChild();
|
2005-06-07 19:22:20 +06:00
|
|
|
while (childItem) {
|
|
|
|
if (childItem->text(0) == aHypData->PluginName) {
|
2004-06-18 14:34:31 +06:00
|
|
|
parentItem = childItem;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
childItem = childItem->nextSibling();
|
|
|
|
}
|
2005-06-07 19:22:20 +06:00
|
|
|
if (!parentItem)
|
|
|
|
parentItem = new QListViewItem(ListAlgoDefinition, aHypData->PluginName);
|
|
|
|
parentItem->setOpen(true);
|
|
|
|
QListViewItem* aItem = new QListViewItem(parentItem, aHypData->Label, HypList[i]);
|
|
|
|
QPixmap aPixMap (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr(aHypData->IconId)));
|
|
|
|
if (!aPixMap.isNull())
|
|
|
|
aItem->setPixmap(0, aPixMap);
|
2004-06-18 14:34:31 +06:00
|
|
|
}
|
|
|
|
}
|