2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
|
2004-12-01 15:39:14 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
2004-12-01 15:39:14 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05: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.
|
2004-12-01 15:39:14 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
|
|
|
//
|
|
|
|
// GEOM GEOMGUI : GUI for Geometry component
|
|
|
|
// File : BooleanGUI_Dialog.cxx
|
|
|
|
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
|
2004-12-01 15:39:14 +05:00
|
|
|
//
|
|
|
|
#include "BooleanGUI.h"
|
2009-02-13 17:16:39 +05:00
|
|
|
#include "BooleanGUI_Dialog.h"
|
2005-06-02 13:17:09 +06:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
#include <DlgRef.h>
|
|
|
|
#include <GeometryGUI.h>
|
|
|
|
#include <GEOMBase.h>
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
#include <SUIT_Session.h>
|
|
|
|
#include <SUIT_ResourceMgr.h>
|
|
|
|
#include <SalomeApp_Application.h>
|
|
|
|
#include <LightApp_SelectionMgr.h>
|
2005-08-26 11:29:57 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
//=================================================================================
|
|
|
|
// class : BooleanGUI_Dialog()
|
|
|
|
// purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
|
|
|
|
// 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.
|
|
|
|
//=================================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
|
|
|
|
QWidget* parent, bool modal, Qt::WindowFlags fl)
|
|
|
|
: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
|
|
|
|
myOperation(theOperation)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
QPixmap image0;
|
|
|
|
QString aTitle, aCaption;
|
2009-02-13 17:16:39 +05:00
|
|
|
switch (myOperation) {
|
|
|
|
case BooleanGUI::COMMON:
|
|
|
|
image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
|
|
|
|
aTitle = tr("GEOM_COMMON");
|
|
|
|
aCaption = tr("GEOM_COMMON_TITLE");
|
|
|
|
setHelpFileName("common_operation_page.html");
|
|
|
|
break;
|
|
|
|
case BooleanGUI::CUT:
|
|
|
|
image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
|
|
|
|
aTitle = tr("GEOM_CUT");
|
|
|
|
aCaption = tr("GEOM_CUT_TITLE");
|
|
|
|
setHelpFileName("cut_operation_page.html");
|
|
|
|
break;
|
|
|
|
case BooleanGUI::FUSE:
|
|
|
|
image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
|
|
|
|
aTitle = tr("GEOM_FUSE");
|
|
|
|
aCaption = tr("GEOM_FUSE_TITLE");
|
|
|
|
setHelpFileName("fuse_operation_page.html");
|
|
|
|
break;
|
|
|
|
case BooleanGUI::SECTION:
|
|
|
|
image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
|
|
|
|
aTitle = tr("GEOM_SECTION");
|
|
|
|
aCaption = tr("GEOM_SECTION_TITLE");
|
|
|
|
setHelpFileName("section_opeartion_page.html");
|
|
|
|
break;
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
setWindowTitle(aCaption);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
/***************************************************************/
|
2009-02-13 17:16:39 +05:00
|
|
|
mainFrame()->GroupConstructors->setTitle(aTitle);
|
|
|
|
mainFrame()->RadioButton1->setIcon(image0);
|
|
|
|
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
mainFrame()->RadioButton2->close();
|
|
|
|
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
mainFrame()->RadioButton3->close();
|
|
|
|
|
|
|
|
myGroup = new DlgRef_2Sel(centralWidget());
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
|
2009-02-13 17:16:39 +05:00
|
|
|
if (myOperation != BooleanGUI::CUT) {
|
|
|
|
myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
|
|
|
|
myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
else {
|
|
|
|
myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
|
|
|
|
myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
myGroup->PushButton1->setIcon(image1);
|
|
|
|
myGroup->PushButton2->setIcon(image1);
|
|
|
|
myGroup->LineEdit1->setReadOnly(true);
|
|
|
|
myGroup->LineEdit2->setReadOnly(true);
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
|
|
|
|
layout->setMargin(0); layout->setSpacing(6);
|
|
|
|
layout->addWidget(myGroup);
|
2004-12-01 15:39:14 +05:00
|
|
|
/***************************************************************/
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
// Initialisation
|
2004-12-01 15:39:14 +05:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ~BooleanGUI_Dialog()
|
|
|
|
// purpose : Destroys the object and frees any allocated resources
|
|
|
|
//=================================================================================
|
|
|
|
BooleanGUI_Dialog::~BooleanGUI_Dialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : Init()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::Init()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
mainFrame()->GroupBoxPublish->show();
|
|
|
|
|
|
|
|
// init variables
|
2004-12-01 15:39:14 +05:00
|
|
|
myEditCurrentArgument = myGroup->LineEdit1;
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
myGroup->LineEdit1->setText("");
|
|
|
|
myGroup->LineEdit2->setText("");
|
|
|
|
myObject1 = myObject2 = GEOM::GEOM_Object::_nil();
|
|
|
|
|
|
|
|
// signals and slots connections
|
|
|
|
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
|
|
|
|
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
|
|
|
|
connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
|
|
|
|
|
|
|
|
connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
|
|
|
|
connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
|
|
|
|
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
initName(mainFrame()->GroupConstructors->title());
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
|
|
|
|
setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
|
|
|
|
setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
mainFrame()->RadioButton1->setFocus();
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
globalSelection(GEOM_ALLSHAPES);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
myGroup->PushButton1->click();
|
|
|
|
SelectionIntoArgument();
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnOk()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::ClickOnOk()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
if (ClickOnApply())
|
2004-12-01 15:39:14 +05:00
|
|
|
ClickOnCancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnApply()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool BooleanGUI_Dialog::ClickOnApply()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!onAccept())
|
|
|
|
return false;
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
initName();
|
2009-02-13 17:16:39 +05:00
|
|
|
// activate selection and connect selection manager
|
|
|
|
myGroup->PushButton1->click();
|
2004-12-01 15:39:14 +05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : SelectionIntoArgument()
|
2009-02-13 17:16:39 +05:00
|
|
|
// purpose : Called when selection is changed or on dialog initialization or activation
|
2004-12-01 15:39:14 +05:00
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::SelectionIntoArgument()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
myEditCurrentArgument->setText("");
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
|
|
|
|
SALOME_ListIO aSelList;
|
|
|
|
aSelMgr->selectedObjects(aSelList);
|
|
|
|
|
|
|
|
if (aSelList.Extent() != 1) {
|
|
|
|
if (myEditCurrentArgument == myGroup->LineEdit1) myObject1 = GEOM::GEOM_Object::_nil();
|
|
|
|
else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2 = GEOM::GEOM_Object::_nil();
|
2004-12-01 15:39:14 +05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nbSel == 1
|
|
|
|
Standard_Boolean aRes = Standard_False;
|
2009-02-13 17:16:39 +05:00
|
|
|
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
|
|
|
|
if (!CORBA::is_nil(aSelectedObject) && aRes && GEOMBase::IsShape(aSelectedObject))
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
|
|
|
|
|
|
|
|
// clear selection
|
|
|
|
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
|
|
|
|
myGeomGUI->getApp()->selectionMgr()->clearSelected();
|
|
|
|
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
|
|
|
|
this, SLOT(SelectionIntoArgument()));
|
|
|
|
|
|
|
|
if (myEditCurrentArgument == myGroup->LineEdit1) {
|
|
|
|
myObject1 = aSelectedObject;
|
|
|
|
if (myObject2->_is_nil())
|
|
|
|
myGroup->PushButton2->click();
|
|
|
|
}
|
|
|
|
else if (myEditCurrentArgument == myGroup->LineEdit2) {
|
|
|
|
myObject2 = aSelectedObject;
|
|
|
|
if (myObject1->_is_nil())
|
|
|
|
myGroup->PushButton1->click();
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : SetEditCurrentArgument()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::SetEditCurrentArgument()
|
|
|
|
{
|
|
|
|
QPushButton* send = (QPushButton*)sender();
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
if (send == myGroup->PushButton1) {
|
|
|
|
myEditCurrentArgument = myGroup->LineEdit1;
|
|
|
|
|
|
|
|
myGroup->PushButton2->setDown(false);
|
|
|
|
myGroup->LineEdit2->setEnabled(false);
|
|
|
|
}
|
|
|
|
else if (send == myGroup->PushButton2) {
|
|
|
|
myEditCurrentArgument = myGroup->LineEdit2;
|
|
|
|
|
|
|
|
myGroup->PushButton1->setDown(false);
|
|
|
|
myGroup->LineEdit1->setEnabled(false);
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
// enable line edit
|
|
|
|
myEditCurrentArgument->setEnabled(true);
|
2004-12-01 15:39:14 +05:00
|
|
|
myEditCurrentArgument->setFocus();
|
2009-02-13 17:16:39 +05:00
|
|
|
// after setFocus(), because it will be setDown(false) when loses focus
|
|
|
|
send->setDown(true);
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : LineEditReturnPressed()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::LineEditReturnPressed()
|
|
|
|
{
|
|
|
|
QLineEdit* send = (QLineEdit*)sender();
|
2009-02-13 17:16:39 +05:00
|
|
|
if (send == myGroup->LineEdit1 || send == myGroup->LineEdit2) {
|
2004-12-01 15:39:14 +05:00
|
|
|
myEditCurrentArgument = send;
|
|
|
|
GEOMBase_Skeleton::LineEditReturnPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ActivateThisDialog()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::ActivateThisDialog()
|
|
|
|
{
|
|
|
|
GEOMBase_Skeleton::ActivateThisDialog();
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
|
|
|
|
this, SLOT( SelectionIntoArgument() ) );
|
|
|
|
displayPreview();
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : enterEvent()
|
|
|
|
// purpose : when mouse enter onto the QWidget
|
|
|
|
//=================================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
void BooleanGUI_Dialog::enterEvent (QEvent*)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!mainFrame()->GroupConstructors->isEnabled())
|
2004-12-01 15:39:14 +05:00
|
|
|
ActivateThisDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : createOperation
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
|
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
return getGeomEngine()->GetIBooleanOperations(getStudyId());
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : isValid
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
bool BooleanGUI_Dialog::isValid (QString&)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
//Handle(SALOME_InteractiveObject) IO = firstIObject();
|
|
|
|
//Standard_Boolean testResult;
|
|
|
|
//GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject(IO, testResult);
|
|
|
|
//if (!testResult || anObject->_is_nil())
|
|
|
|
// return false;
|
2008-03-07 12:45:34 +05:00
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
return !CORBA::is_nil(myObject1) && !CORBA::is_nil(myObject2);
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : execute
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
bool BooleanGUI_Dialog::execute (ObjectList& objects)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var anObj;
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
|
|
|
|
MakeBoolean(myObject1, myObject2, myOperation);
|
|
|
|
if (!anObj->_is_nil())
|
|
|
|
objects.push_back(anObj._retn());
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : restoreSubShapes
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
|
|
|
|
SALOMEDS::SObject_ptr theSObject)
|
|
|
|
{
|
|
|
|
if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
|
|
|
|
// empty list of arguments means that all arguments should be restored
|
|
|
|
getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
|
|
|
|
/*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
|
|
|
|
/*theInheritFirstArg=*/myOperation == BooleanGUI::CUT); // ? false
|
|
|
|
}
|
|
|
|
}
|