2016-09-30 12:01:23 +03:00
|
|
|
// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
|
|
|
//
|
|
|
|
// 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, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
|
|
|
|
// File : MeasureGUI_AnnotationDlg.cxx
|
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
#include "MeasureGUI.h"
|
2016-09-30 12:01:23 +03:00
|
|
|
#include "MeasureGUI_AnnotationDlg.h"
|
2016-10-07 21:18:28 +03:00
|
|
|
#include "MeasureGUI_AnnotationInteractor.h"
|
2016-09-30 12:01:23 +03:00
|
|
|
|
|
|
|
#include <DlgRef.h>
|
|
|
|
#include <GEOMBase.h>
|
|
|
|
#include <GEOMBase_Skeleton.h>
|
|
|
|
#include <GEOM_Displayer.h>
|
|
|
|
#include <GeometryGUI.h>
|
|
|
|
#include <GEOM_Annotation.hxx>
|
|
|
|
|
|
|
|
#include <SOCC_Prs.h>
|
|
|
|
#include <SOCC_ViewModel.h>
|
|
|
|
|
|
|
|
#include <SalomeApp_Application.h>
|
|
|
|
#include <SalomeApp_Study.h>
|
|
|
|
#include <SalomeApp_Tools.h>
|
|
|
|
#include <SalomeApp_IntSpinBox.h>
|
|
|
|
#include <SalomeApp_DoubleSpinBox.h>
|
|
|
|
|
|
|
|
#include <LightApp_SelectionMgr.h>
|
|
|
|
|
|
|
|
#include <OCCViewer_ViewModel.h>
|
|
|
|
#include <OCCViewer_ViewManager.h>
|
|
|
|
#include <SVTK_ViewModel.h>
|
|
|
|
#include <SALOME_Prs.h>
|
|
|
|
#include <SALOME_ListIO.hxx>
|
|
|
|
|
|
|
|
#include <SUIT_Desktop.h>
|
|
|
|
#include <SUIT_MessageBox.h>
|
|
|
|
#include <SUIT_OverrideCursor.h>
|
|
|
|
#include <SUIT_ResourceMgr.h>
|
|
|
|
#include <SUIT_Session.h>
|
|
|
|
#include <SUIT_ViewWindow.h>
|
|
|
|
#include <SUIT_ViewManager.h>
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include <AIS_ListOfInteractive.hxx>
|
|
|
|
#include <AIS_ListIteratorOfListOfInteractive.hxx>
|
|
|
|
|
|
|
|
#include <TopExp.hxx>
|
|
|
|
#include <TopExp_Explorer.hxx>
|
|
|
|
#include <TopTools_IndexedMapOfShape.hxx>
|
|
|
|
#include <TColStd_IndexedMapOfInteger.hxx>
|
|
|
|
#include <TColStd_MapOfInteger.hxx>
|
|
|
|
#include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include <SALOMEDS_wrap.hxx>
|
|
|
|
#include <GEOMImpl_Types.hxx>
|
|
|
|
|
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : MeasureGUI_AnnotationDlg
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, const bool theIsCreate,
|
|
|
|
QWidget* parent, bool modal, Qt::WindowFlags fl )
|
|
|
|
: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
|
|
|
|
myIsCreation( theIsCreate )
|
2016-09-30 12:01:23 +03:00
|
|
|
{
|
2016-10-05 12:42:03 +03:00
|
|
|
myEditCurrentArgument = 0;
|
|
|
|
|
|
|
|
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
|
|
|
|
QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
setWindowTitle( myIsCreation ? tr("CREATE_ANNOTATION_TITLE") : tr("EDIT_ANNOTATION_TITLE"));
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
// Shape type button group
|
|
|
|
mainFrame()->GroupConstructors->hide();
|
|
|
|
|
|
|
|
// Field name
|
|
|
|
mainFrame()->GroupBoxName->setTitle(tr("ANNOTATION_NAME"));
|
|
|
|
|
|
|
|
// Field properties
|
|
|
|
QGroupBox* propGroup = new QGroupBox(tr("ANNOTATION_PROPERTIES"), centralWidget());
|
|
|
|
QGridLayout* propLayout = new QGridLayout(propGroup);
|
|
|
|
propLayout->setMargin(9);
|
|
|
|
propLayout->setSpacing(6);
|
|
|
|
|
|
|
|
QLabel* textLabel = new QLabel(tr("ANNOTATION_TEXT"), propGroup);
|
|
|
|
myTextEdit = new QLineEdit(propGroup);
|
|
|
|
propLayout->addWidget(textLabel, 0, 0);
|
|
|
|
propLayout->addWidget(myTextEdit, 0, 1, 1, 2);
|
|
|
|
|
|
|
|
// shape
|
|
|
|
QLabel* shapeLabel = new QLabel(tr("ANNOTATION_SHAPE"), propGroup);
|
|
|
|
myShapeSelBtn = new QPushButton(propGroup);
|
|
|
|
myShapeSelBtn->setIcon(iconSelect);
|
|
|
|
myShapeSelBtn->setEnabled(myIsCreation);
|
|
|
|
myShapeName = new QLineEdit(propGroup);
|
|
|
|
myShapeName->setReadOnly(true);
|
|
|
|
myShapeName->setEnabled(myIsCreation);
|
|
|
|
|
|
|
|
// data type
|
|
|
|
QLabel* typeLabel = new QLabel(tr("ANNOTATION_TYPE"), propGroup);
|
|
|
|
myTypeCombo = new QComboBox(propGroup);
|
|
|
|
myTypeCombo->insertItem(0, tr("3D"));
|
|
|
|
myTypeCombo->insertItem(1, tr("2D"));
|
2016-10-11 17:44:18 +03:00
|
|
|
myTypeCombo->setCurrentIndex(0); // 3D, not fixed
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
propLayout->addWidget(shapeLabel, 1, 0);
|
|
|
|
propLayout->addWidget(myShapeSelBtn, 1, 1);
|
|
|
|
propLayout->addWidget(myShapeName, 1, 2);
|
2016-10-11 17:44:18 +03:00
|
|
|
propLayout->addWidget(typeLabel, 2, 0, 1, 2);
|
|
|
|
propLayout->addWidget(myTypeCombo, 2, 2);
|
2016-10-05 12:42:03 +03:00
|
|
|
propLayout->setColumnStretch(2, 5);
|
|
|
|
|
|
|
|
QLabel* shapeTypeLabel = new QLabel(tr("ANNOTATION_SUB_SHAPE"), propGroup);
|
|
|
|
mySubShapeTypeCombo = new QComboBox(propGroup);
|
2016-10-06 14:33:25 +03:00
|
|
|
mySubShapeTypeCombo->addItem(tr("WHOLE_SHAPE"), TopAbs_SHAPE);
|
|
|
|
mySubShapeTypeCombo->addItem(tr("GEOM_VERTEX"), TopAbs_VERTEX);
|
|
|
|
mySubShapeTypeCombo->addItem(tr("GEOM_EDGE"), TopAbs_EDGE);
|
|
|
|
mySubShapeTypeCombo->addItem(tr("GEOM_FACE"), TopAbs_FACE);
|
|
|
|
mySubShapeTypeCombo->addItem(tr("GEOM_SOLID"), TopAbs_SOLID);
|
2016-10-11 17:44:18 +03:00
|
|
|
mySubShapeTypeCombo->setCurrentIndex(0); // SHAPE
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
propLayout->addWidget(shapeTypeLabel, 3, 0);
|
|
|
|
propLayout->addWidget(mySubShapeTypeCombo, 3, 1, 1, 2);
|
|
|
|
|
|
|
|
// sub-shape
|
|
|
|
mySubShapeSelBtn = new QPushButton(propGroup);
|
|
|
|
mySubShapeSelBtn->setIcon(iconSelect);
|
|
|
|
mySubShapeSelBtn->setEnabled(myIsCreation);
|
|
|
|
mySubShapeName = new QLineEdit(propGroup);
|
|
|
|
mySubShapeName->setReadOnly(true);
|
|
|
|
mySubShapeName->setEnabled(myIsCreation);
|
|
|
|
|
|
|
|
propLayout->addWidget(mySubShapeSelBtn, 4, 1);
|
|
|
|
propLayout->addWidget(mySubShapeName, 4, 2);
|
|
|
|
|
|
|
|
// Field properties
|
2016-10-11 17:44:18 +03:00
|
|
|
QGroupBox* styleGroup = new QGroupBox(tr("ANNOTATION_STYLE"),
|
|
|
|
centralWidget());
|
2016-10-05 12:42:03 +03:00
|
|
|
QGridLayout* styleLayout = new QGridLayout(styleGroup);
|
|
|
|
styleLayout->setMargin(9);
|
|
|
|
styleLayout->setSpacing(6);
|
|
|
|
|
|
|
|
QLabel* fontLabel = new QLabel(tr("ANNOTATION_FONT"), styleGroup);
|
|
|
|
styleLayout->addWidget(fontLabel, 0, 0);
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
|
|
|
|
layout->setMargin(0);
|
|
|
|
layout->setSpacing(6);
|
|
|
|
layout->addWidget(propGroup);
|
|
|
|
layout->addWidget(styleGroup);
|
|
|
|
|
|
|
|
setHelpFileName("annotation_page.html");
|
|
|
|
|
|
|
|
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
|
|
|
|
connect(aSelMgr, SIGNAL(currentSelectionChanged()), this,
|
2016-10-11 17:44:18 +03:00
|
|
|
SLOT(SelectionIntoArgument()));
|
2016-10-05 12:42:03 +03:00
|
|
|
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
|
|
|
|
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
|
|
|
|
|
2016-10-07 21:18:28 +03:00
|
|
|
myInteractor = new MeasureGUI_AnnotationInteractor( theGeometryGUI, parent );
|
|
|
|
myInteractor->Enable();
|
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
Init();
|
|
|
|
//updateState();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : ~MeasureGUI_AnnotationDlg
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() {
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : Init()
|
2016-10-05 12:42:03 +03:00
|
|
|
// purpose : fills annotation properties with default values(in create mode) or
|
|
|
|
// the values of modified object
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::Init() {
|
2016-10-05 12:42:03 +03:00
|
|
|
if (myIsCreation) {
|
|
|
|
initName(tr("ANNOTATION_PREFIX"));
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
// default presentation values
|
2016-10-12 11:08:05 +03:00
|
|
|
myAnnotationProperties.Name = getNewObjectName();
|
2016-10-07 21:35:07 +03:00
|
|
|
myAnnotationProperties.Position = gp_Pnt(250, 250, 250);
|
2016-10-06 14:33:25 +03:00
|
|
|
myAnnotationProperties.Text = tr("ANNOTATION_PREFIX");
|
2016-10-12 11:08:05 +03:00
|
|
|
myAnnotationProperties.IsVisible = false;
|
2016-10-06 14:33:25 +03:00
|
|
|
myAnnotationProperties.IsScreenFixed = false;
|
|
|
|
myAnnotationProperties.Attach = gp_Pnt(0, 0, 0);
|
|
|
|
myAnnotationProperties.ShapeIndex = -1;
|
2016-10-11 17:44:18 +03:00
|
|
|
myAnnotationProperties.ShapeType = (int) TopAbs_SHAPE;
|
|
|
|
|
|
|
|
// update internal controls and fields following to default values
|
|
|
|
activateSelectionArgument(myShapeSelBtn);
|
|
|
|
myTextEdit->setText(myAnnotationProperties.Text);
|
|
|
|
myTypeCombo->setCurrentIndex(!myAnnotationProperties.IsScreenFixed);
|
|
|
|
|
|
|
|
int aSubShapeTypeIndex = -1;
|
|
|
|
int aTypesCount = aTypesCount = mySubShapeTypeCombo->count();
|
|
|
|
for (int i = 0; i < aTypesCount && aSubShapeTypeIndex < 0; i++) {
|
|
|
|
int aType = mySubShapeTypeCombo->itemData(i).toInt();
|
|
|
|
if (aType == myAnnotationProperties.ShapeType)
|
|
|
|
aSubShapeTypeIndex = i;
|
|
|
|
}
|
|
|
|
mySubShapeTypeCombo->setCurrentIndex(aSubShapeTypeIndex);
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
mySelectionMode = (TopAbs_ShapeEnum) myAnnotationProperties.ShapeType;
|
2016-10-05 12:42:03 +03:00
|
|
|
SelectionIntoArgument();
|
2016-10-11 17:44:18 +03:00
|
|
|
updateSubShapeEnableState();
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
// connect controls
|
|
|
|
connect(myShapeSelBtn, SIGNAL(clicked()), this,
|
|
|
|
SLOT(SetEditCurrentArgument()));
|
|
|
|
connect(mySubShapeSelBtn, SIGNAL(clicked()), this,
|
|
|
|
SLOT(SetEditCurrentArgument()));
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
connect(myTextEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChange()));
|
|
|
|
connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeChange()));
|
|
|
|
connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
|
this, SLOT(onSubShapeTypeChange()));
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-07 21:35:07 +03:00
|
|
|
//SelectionIntoArgument();
|
2016-10-11 17:44:18 +03:00
|
|
|
} else { // edition
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
|
|
|
redisplayPreview();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:33:25 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : activateSelection
|
|
|
|
// purpose : Activate local selection
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::activateSelection() {
|
2016-10-07 21:35:07 +03:00
|
|
|
//globalSelection(GEOM_ALLSHAPES);
|
|
|
|
//if (!myShape->_is_nil() && mySelectionMode != TopAbs_SHAPE) {
|
|
|
|
// localSelection(myShape.get(), mySelectionMode);
|
|
|
|
//}
|
2016-10-06 14:33:25 +03:00
|
|
|
}
|
|
|
|
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : getShapeType()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const {
|
|
|
|
return (TopAbs_ShapeEnum) mySubShapeTypeCombo->itemData(
|
|
|
|
mySubShapeTypeCombo->currentIndex()).toInt();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnOk()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::ClickOnOk() {
|
|
|
|
setIsApplyAndClose(true);
|
|
|
|
if (ClickOnApply())
|
|
|
|
ClickOnCancel();
|
|
|
|
setIsApplyAndClose(false);
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : ClickOnApply()
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
bool MeasureGUI_AnnotationDlg::ClickOnApply() {
|
|
|
|
if (!isApplyAndClose()) {
|
|
|
|
setIsDisableBrowsing(true);
|
|
|
|
setIsDisplayResult(false);
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
QString msg;
|
|
|
|
if (!isValid(msg)) {
|
|
|
|
showError(msg);
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-06 14:33:25 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
SUIT_OverrideCursor wc;
|
|
|
|
SUIT_Session::session()->activeApplication()->putInfo("");
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (openCommand())
|
|
|
|
if (!execute(/*isApplyAndClose()*/)) {
|
2016-09-30 12:01:23 +03:00
|
|
|
abortCommand();
|
2016-10-11 17:44:18 +03:00
|
|
|
showError();
|
2016-09-30 12:01:23 +03:00
|
|
|
return false;
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
|
|
|
} catch (const SALOME::SALOME_Exception& e) {
|
|
|
|
SalomeApp_Tools::QtCatchCorbaException(e);
|
|
|
|
abortCommand();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
commitCommand();
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
if (!isApplyAndClose()) {
|
|
|
|
setIsDisableBrowsing(false);
|
|
|
|
setIsDisplayResult(true);
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
/*if (myIsCreation)
|
|
|
|
{
|
|
|
|
myAnnotation = GEOM::GEOM_Field::_nil();
|
|
|
|
if (!isApplyAndClose())
|
|
|
|
Init();
|
|
|
|
}*/
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : SetEditCurrentArgument()
|
2016-10-05 12:42:03 +03:00
|
|
|
// purpose : process click on shape/sub-shape button. It stores as current edit argument
|
|
|
|
// the corresponded line edit, set focus in it and unpress other button if it was pressed
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() {
|
|
|
|
QPushButton* aSelectButton = (QPushButton*) sender();
|
|
|
|
|
|
|
|
activateSelectionArgument(aSelectButton);
|
|
|
|
|
|
|
|
SelectionIntoArgument();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : activateSelectionArgument()
|
|
|
|
// purpose : it stores as current edit argument the corresponded line edit,
|
|
|
|
// sets the focus on it and unpresses other button if it was pressed
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_AnnotationDlg::activateSelectionArgument(
|
|
|
|
QPushButton* theSelectionButton) {
|
2016-10-05 12:42:03 +03:00
|
|
|
QPushButton* anOtherButton = 0;
|
2016-10-11 17:44:18 +03:00
|
|
|
if (theSelectionButton == myShapeSelBtn) {
|
2016-10-05 12:42:03 +03:00
|
|
|
myEditCurrentArgument = myShapeName;
|
|
|
|
anOtherButton = mySubShapeSelBtn;
|
2016-10-11 17:44:18 +03:00
|
|
|
} else if (theSelectionButton == mySubShapeSelBtn) {
|
2016-10-05 12:42:03 +03:00
|
|
|
myEditCurrentArgument = mySubShapeName;
|
|
|
|
anOtherButton = myShapeSelBtn;
|
2016-10-11 17:44:18 +03:00
|
|
|
} else
|
2016-10-05 12:42:03 +03:00
|
|
|
myEditCurrentArgument = 0;
|
|
|
|
|
|
|
|
if (myEditCurrentArgument)
|
2016-09-30 12:01:23 +03:00
|
|
|
myEditCurrentArgument->setFocus();
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
theSelectionButton->setDown(true);
|
|
|
|
anOtherButton->setDown(false);
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : SelectionIntoArgument()
|
2016-10-05 12:42:03 +03:00
|
|
|
// purpose : Called when selection has changed. Sets the current selection in the
|
|
|
|
// annotation property and redisplays presentation
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::SelectionIntoArgument() {
|
2016-10-05 12:42:03 +03:00
|
|
|
if (myIsCreation && myEditCurrentArgument) {
|
2016-10-11 17:44:18 +03:00
|
|
|
myEditCurrentArgument->setText("");
|
2016-10-05 12:42:03 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
GEOM::GeomObjPtr anObj = getSelected(mySelectionMode);
|
2016-10-05 12:42:03 +03:00
|
|
|
|
2016-10-06 14:33:25 +03:00
|
|
|
gp_Pnt anAttachPoint(0, 0, 0);
|
2016-10-05 12:42:03 +03:00
|
|
|
int aSubShapeIndex = -1;
|
|
|
|
if (myEditCurrentArgument == myShapeName) { // Selection of a shape is active
|
2016-10-11 17:44:18 +03:00
|
|
|
if (anObj->_is_nil() || mySelectionMode != TopAbs_SHAPE) {
|
|
|
|
myShape = GEOM::GEOM_Object::_nil();
|
|
|
|
} else {
|
|
|
|
myShape = anObj;
|
|
|
|
QString aName = GEOMBase::GetName(anObj.get());
|
2016-10-06 14:33:25 +03:00
|
|
|
myEditCurrentArgument->setText(aName);
|
2016-10-11 17:44:18 +03:00
|
|
|
}
|
2016-10-05 12:42:03 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
bool aNullShape = myShape->_is_nil();
|
|
|
|
mySubShapeTypeCombo->setEnabled(!aNullShape);
|
|
|
|
updateSubShapeEnableState();
|
2016-10-05 12:42:03 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
activateSelection();
|
2016-10-06 14:33:25 +03:00
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
if (!myShape->_is_nil()) {
|
|
|
|
TopoDS_Shape aShape;
|
|
|
|
GEOMBase::GetShape(myShape.get(), aShape);
|
|
|
|
anAttachPoint = getAttachPoint(aShape);
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
} else if (myEditCurrentArgument == mySubShapeName) {
|
2016-10-05 12:42:03 +03:00
|
|
|
if (!myShape->_is_nil()) {
|
2016-10-11 17:44:18 +03:00
|
|
|
QString aName = GEOMBase::GetName(anObj.get());
|
2016-10-06 14:33:25 +03:00
|
|
|
myEditCurrentArgument->setText(aName);
|
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
TopTools_IndexedMapOfShape aMainMap;
|
|
|
|
TopoDS_Shape aMainShape;
|
|
|
|
GEOMBase::GetShape(myShape.get(), aMainShape);
|
|
|
|
TopExp::MapShapes(aMainShape, aMainMap);
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
TopExp_Explorer anExp(aMainShape, getShapeType());
|
2016-10-05 12:42:03 +03:00
|
|
|
bool isShowWarning = true;
|
|
|
|
|
|
|
|
TopoDS_Shape aSubShape;
|
|
|
|
for (; anExp.More() && aSubShapeIndex < 0; anExp.Next()) {
|
|
|
|
TopoDS_Shape aCurrentSubShape = anExp.Current();
|
|
|
|
int anIndex = aMainMap.FindIndex(aCurrentSubShape);
|
|
|
|
if (anIndex >= 0) {
|
|
|
|
aSubShapeIndex = anIndex;
|
|
|
|
aSubShape = aCurrentSubShape;
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
2016-10-05 12:42:03 +03:00
|
|
|
anAttachPoint = getAttachPoint(aSubShape);
|
2016-10-11 17:44:18 +03:00
|
|
|
myAnnotationProperties.ShapeIndex = aSubShapeIndex;
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
2016-10-05 12:42:03 +03:00
|
|
|
myAnnotationProperties.Attach = anAttachPoint;
|
|
|
|
}
|
2016-10-11 17:44:18 +03:00
|
|
|
redisplayPreview();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : onTextChange
|
2016-10-05 12:42:03 +03:00
|
|
|
//purpose : change annotation text
|
2016-09-30 12:01:23 +03:00
|
|
|
//=======================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::onTextChange() {
|
2016-10-05 12:42:03 +03:00
|
|
|
myAnnotationProperties.Text = myTextEdit->text();
|
|
|
|
redisplayPreview();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : onTypeChange
|
2016-10-05 12:42:03 +03:00
|
|
|
//purpose : change annotation type: 2D or 3D
|
2016-09-30 12:01:23 +03:00
|
|
|
//=======================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::onTypeChange() {
|
2016-10-05 12:42:03 +03:00
|
|
|
myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1;
|
|
|
|
redisplayPreview();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
//function : onSubShapeTypeChange
|
|
|
|
//purpose :
|
|
|
|
//=======================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() {
|
|
|
|
activateSelectionArgument(mySubShapeSelBtn);
|
|
|
|
|
2016-10-06 14:33:25 +03:00
|
|
|
TopAbs_ShapeEnum aShapeType = getShapeType();
|
|
|
|
myAnnotationProperties.ShapeType = aShapeType;
|
2016-10-11 17:44:18 +03:00
|
|
|
if (aShapeType != mySelectionMode) {
|
|
|
|
mySubShapeName->setText("");
|
|
|
|
myAnnotationProperties.ShapeIndex = -1;
|
|
|
|
mySelectionMode = aShapeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubShapeEnableState();
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-06 14:33:25 +03:00
|
|
|
activateSelection();
|
2016-10-05 12:42:03 +03:00
|
|
|
redisplayPreview();
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define RETURN_WITH_MSG(a, b) \
|
|
|
|
if ((a)) { \
|
|
|
|
theMessage += (b); \
|
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:08:05 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : createOperation
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
GEOM::GEOM_IOperations_ptr MeasureGUI_AnnotationDlg::createOperation()
|
|
|
|
{
|
|
|
|
return getGeomEngine()->GetILocalOperations(getStudyId());
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : isValid()
|
|
|
|
// purpose : Verify validity of input data
|
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) {
|
2016-10-05 12:42:03 +03:00
|
|
|
SalomeApp_Study* study = getStudy();
|
|
|
|
RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY"))
|
|
|
|
RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(),
|
2016-10-11 17:44:18 +03:00
|
|
|
tr("GEOM_STUDY_LOCKED"))
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
if (myIsCreation) {
|
2016-10-06 14:33:25 +03:00
|
|
|
RETURN_WITH_MSG(myShape->_is_nil(), tr("NO_SHAPE"))
|
2016-10-11 17:44:18 +03:00
|
|
|
} else {
|
2016-10-05 12:42:03 +03:00
|
|
|
//RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD"))
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
if (getShapeType() != TopAbs_SHAPE) {
|
2016-09-30 12:01:23 +03:00
|
|
|
if (myIsCreation) {
|
2016-10-06 14:33:25 +03:00
|
|
|
RETURN_WITH_MSG(myAnnotationProperties.ShapeIndex < 0, tr("NO_SUB_SHAPE"))
|
2016-10-11 17:44:18 +03:00
|
|
|
} else {
|
2016-10-05 12:42:03 +03:00
|
|
|
//RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD"))
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : execute
|
|
|
|
// purpose :
|
|
|
|
//=================================================================================
|
|
|
|
bool MeasureGUI_AnnotationDlg::execute()
|
|
|
|
{
|
|
|
|
QString anError;
|
|
|
|
if (!isValid(anError))
|
|
|
|
return false;
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
if (myIsCreation) {
|
2016-10-11 17:44:18 +03:00
|
|
|
SalomeApp_Study* aStudy = getStudy();
|
|
|
|
GEOMGUI_ShapeAnnotations aProp =
|
|
|
|
aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
|
|
|
|
myShape->GetStudyEntry(),
|
|
|
|
GEOM::propertyName( GEOM::ShapeAnnotations ),
|
|
|
|
QVariant() )
|
|
|
|
.value<GEOMGUI_ShapeAnnotations>();
|
|
|
|
|
|
|
|
// append new dimension record to data
|
2016-10-12 11:08:05 +03:00
|
|
|
int aPropId = aProp.GetNumber() - 1;
|
|
|
|
myAnnotationProperties.Name = getNewObjectName(); // update here as we do not listen name modification
|
|
|
|
myAnnotationProperties.IsVisible = true; // initially created annotation is hidden
|
2016-10-11 17:44:18 +03:00
|
|
|
aProp.Add( myAnnotationProperties );
|
|
|
|
|
|
|
|
// store modified property data
|
|
|
|
aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
|
|
|
|
myShape->GetStudyEntry(), GEOM::propertyName(GEOM::ShapeAnnotations),
|
|
|
|
aProp);
|
2016-10-12 11:08:05 +03:00
|
|
|
aProp.SaveToAttribute( aStudy, myShape->GetStudyEntry() );
|
2016-10-11 17:44:18 +03:00
|
|
|
myGeomGUI->emitDimensionsUpdated( QString( myShape->GetStudyEntry() ) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*SalomeApp_Study* aStudy = getStudy();
|
|
|
|
myAnnotationProperties = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
|
|
|
|
myShape->GetStudyEntry(),
|
|
|
|
GEOM::propertyName( GEOM::ShapeAnnotations ),
|
|
|
|
QVariant() )
|
|
|
|
.value<GEOMGUI_ShapeAnnotations>();
|
|
|
|
mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );*/
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
|
|
|
return true;
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
2016-10-05 12:42:03 +03:00
|
|
|
// function : buildPrs
|
|
|
|
// purpose : creates annotation presentation object and corresponded SALOME presentation
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() {
|
|
|
|
Handle (GEOM_Annotation)
|
|
|
|
aPresentation = new GEOM_Annotation();
|
2016-09-30 12:01:23 +03:00
|
|
|
|
2016-10-07 21:18:28 +03:00
|
|
|
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
|
|
|
|
const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) );
|
|
|
|
const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 255, 255, 255 ) );
|
|
|
|
const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 255, 255, 255 ) );
|
|
|
|
const double aLineWidth = aResMgr->doubleValue( "Geometry", "shape_annotation_line_width", 1.0 );
|
|
|
|
const int aLineStyle = aResMgr->integerValue( "Geometry", "shape_annotation_line_style", 0 );
|
|
|
|
const bool isAutoHide = aResMgr->booleanValue( "Geometry", "shape_annotation_autohide", false );
|
|
|
|
|
|
|
|
const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB );
|
|
|
|
const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB );
|
|
|
|
const Standard_Real aFontHeight = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
|
|
|
|
|
|
|
|
aPresentation->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) );
|
|
|
|
aPresentation->SetTextHeight( aFontHeight );
|
|
|
|
aPresentation->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) );
|
|
|
|
aPresentation->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) );
|
|
|
|
aPresentation->SetLineWidth( aLineWidth );
|
|
|
|
aPresentation->SetLineStyle( static_cast<Aspect_TypeOfLine>( aLineStyle ) );
|
|
|
|
aPresentation->SetAutoHide( isAutoHide ? Standard_True : Standard_False );
|
|
|
|
|
2016-10-05 12:42:03 +03:00
|
|
|
TopoDS_Shape aShape;
|
|
|
|
GEOMBase::GetShape(myShape.get(), aShape);
|
|
|
|
gp_Ax3 aShapeLCS = gp_Ax3().Transformed(aShape.Location().Transformation());
|
|
|
|
myAnnotationProperties.ToPresentation(aPresentation, aShapeLCS);
|
|
|
|
|
|
|
|
// add Prs to preview
|
|
|
|
SUIT_ViewWindow* vw =
|
2016-10-11 17:44:18 +03:00
|
|
|
SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
|
2016-10-05 12:42:03 +03:00
|
|
|
SOCC_Prs* aPrs =
|
2016-10-11 17:44:18 +03:00
|
|
|
dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs(
|
|
|
|
0));
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
if (aPrs)
|
|
|
|
aPrs->AddObject(aPresentation);
|
|
|
|
|
|
|
|
return aPrs;
|
2016-09-30 12:01:23 +03:00
|
|
|
}
|
|
|
|
|
2016-10-11 17:44:18 +03:00
|
|
|
//=================================================================================
|
|
|
|
// function : updateSubShapeEnableState
|
|
|
|
// purpose : creates annotation presentation object and corresponded SALOME presentation
|
|
|
|
//=================================================================================
|
|
|
|
void MeasureGUI_AnnotationDlg::updateSubShapeEnableState()
|
|
|
|
{
|
|
|
|
bool isWholeShape = getShapeType() == TopAbs_SHAPE;
|
|
|
|
bool aNullShape = myShape->_is_nil();
|
|
|
|
mySubShapeSelBtn->setEnabled(!aNullShape && !isWholeShape);
|
|
|
|
mySubShapeName->setEnabled(!aNullShape && !isWholeShape);
|
|
|
|
}
|
2016-10-05 12:42:03 +03:00
|
|
|
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-05 12:42:03 +03:00
|
|
|
// function : buildPrs
|
|
|
|
// purpose : creates annotation presentation object and corresponded SALOME presentation
|
2016-09-30 12:01:23 +03:00
|
|
|
//=================================================================================
|
2016-10-11 17:44:18 +03:00
|
|
|
void MeasureGUI_AnnotationDlg::redisplayPreview() {
|
2016-10-05 12:42:03 +03:00
|
|
|
QString aMess;
|
|
|
|
if (!isValid(aMess)) {
|
|
|
|
erasePreview(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:08:05 +03:00
|
|
|
erasePreview( false );
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
//SUIT_OverrideCursor wc;
|
|
|
|
//getDisplayer()->SetColor(Quantity_NOC_VIOLET);
|
|
|
|
//getDisplayer()->SetToActivate(false);
|
|
|
|
|
2016-10-12 11:08:05 +03:00
|
|
|
if ( SALOME_Prs* aPrs = buildPrs() )
|
2016-10-05 12:42:03 +03:00
|
|
|
displayPreview(aPrs);
|
2016-10-12 11:08:05 +03:00
|
|
|
} catch ( const SALOME::SALOME_Exception& e ) {
|
|
|
|
SalomeApp_Tools::QtCatchCorbaException( e );
|
2016-10-11 17:44:18 +03:00
|
|
|
} catch (...) {
|
2016-10-05 12:42:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : getAttachPoint
|
|
|
|
// purpose : finds a point on shape to attach annotation object
|
|
|
|
//=================================================================================
|
2016-10-12 11:08:05 +03:00
|
|
|
gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint(const TopoDS_Shape& theShape)
|
|
|
|
{
|
|
|
|
gp_Pnt aPoint = gp_Pnt( 0, 0, 0 );
|
2016-10-05 12:42:03 +03:00
|
|
|
|
|
|
|
return aPoint;
|
|
|
|
}
|
2016-09-30 12:01:23 +03:00
|
|
|
|