From 3a7897bcc7f92755aad0bbe2b05e1e3de73c0dba Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 30 Sep 2016 12:01:23 +0300 Subject: [PATCH] Initial version of annotation dialog --- src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx | 46 +- src/GEOMGUI/GEOMGUI_ShapeAnnotations.h | 7 + src/GEOMGUI/GeometryGUI.cxx | 5 + src/GEOMGUI/GeometryGUI_Operations.h | 2 + src/MeasureGUI/CMakeLists.txt | 3 + src/MeasureGUI/MeasureGUI.cxx | 9 + src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx | 1439 +++++++++++++++++++ src/MeasureGUI/MeasureGUI_AnnotationDlg.h | 213 +++ 8 files changed, 1713 insertions(+), 11 deletions(-) create mode 100644 src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx create mode 100644 src/MeasureGUI/MeasureGUI_AnnotationDlg.h diff --git a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx index 25cb86416..f8fa87d9a 100755 --- a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx +++ b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx @@ -65,6 +65,29 @@ namespace } }; +//================================================================================= +// function : ToPresentation +// purpose : +//================================================================================= +void GEOMGUI_ShapeAnnotations::ShapeAnnotation::ToPresentation( + const Handle(GEOM_Annotation)& theShapeAnnotation, + const gp_Ax3& theLCS ) const +{ + gp_Trsf aToLCS; + aToLCS.SetTransformation( theLCS, gp_Ax3() ); + + // + TCollection_ExtendedString aText; + for (int i = 0; i < (int)Text.length(); i++ ) + aText.Insert( i + 1, Text[ i ].unicode() ); + // + theShapeAnnotation->SetScreenFixed( IsScreenFixed ); + theShapeAnnotation->SetText( aText ); + theShapeAnnotation->SetPosition( Position ); + theShapeAnnotation->SetAttachPoint( Attach.Transformed( aToLCS ) ); +} + + //================================================================================= // function : Constructor // purpose : @@ -246,19 +269,20 @@ void GEOMGUI_ShapeAnnotations::ToPresentation( const int theIndex, const Handle(GEOM_Annotation)& theShapeAnnotation, const gp_Ax3& theLCS ) { - gp_Trsf aToLCS; - aToLCS.SetTransformation( theLCS, gp_Ax3() ); + //gp_Trsf aToLCS; + //aToLCS.SetTransformation( theLCS, gp_Ax3() ); // const ShapeAnnotation& aEntry = myAnnotations[theIndex]; - // - TCollection_ExtendedString aText; - for (int i = 0; i < (int)aEntry.Text.length(); i++ ) - aText.Insert( i + 1, aEntry.Text[ i ].unicode() ); - // - theShapeAnnotation->SetScreenFixed( aEntry.IsScreenFixed ); - theShapeAnnotation->SetText( aText ); - theShapeAnnotation->SetPosition( aEntry.Position ); - theShapeAnnotation->SetAttachPoint( aEntry.Attach.Transformed( aToLCS ) ); + aEntry.ToPresentation(theShapeAnnotation, theLCS); + //// + //TCollection_ExtendedString aText; + //for (int i = 0; i < (int)aEntry.Text.length(); i++ ) + // aText.Insert( i + 1, aEntry.Text[ i ].unicode() ); + //// + //theShapeAnnotation->SetScreenFixed( aEntry.IsScreenFixed ); + //theShapeAnnotation->SetText( aText ); + //theShapeAnnotation->SetPosition( aEntry.Position ); + //theShapeAnnotation->SetAttachPoint( aEntry.Attach.Transformed( aToLCS ) ); } //================================================================================= diff --git a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h index 3c1c2558d..ce18dd5b3 100755 --- a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h +++ b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h @@ -63,6 +63,13 @@ public: gp_Pnt Attach; // attachment point of the annotation int ShapeIndex; // index of the annotated subshape int ShapeType; // type of the annotated subshape + + /*! + * \brief Update presentation properties using the annotation record definition. + * \param theShapeAnnotation [in] the explicit definition of the annotation. + */ + void ToPresentation( const Handle(GEOM_Annotation)& theShapeAnnotation, + const gp_Ax3& theLCS ) const; bool operator == (const ShapeAnnotation& theOther) const { diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index ead10235c..7a65a48d8 100755 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -661,6 +661,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpCheckSelfInters: // MENU MEASURE - CHECK SELF INTERSECTIONS case GEOMOp::OpFastCheckInters: // MENU MEASURE - FAST CHECK INTERSECTIONS case GEOMOp::OpManageDimensions: // MENU MEASURE - MANAGE DIMENSIONS + case GEOMOp::OpAnnotation: // MENU MEASURE - ANNOTATION #ifndef DISABLE_PLOT2DVIEWER case GEOMOp::OpShapeStatistics: // MENU MEASURE - SHAPE STATISTICS #endif @@ -1042,6 +1043,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpMinDistance, "MIN_DIST" ); createGeomAction( GEOMOp::OpAngle, "MEASURE_ANGLE" ); createGeomAction( GEOMOp::OpManageDimensions, "MANAGE_DIMENSIONS" ); + createGeomAction( GEOMOp::OpAnnotation, "ANNOTATION" ); createGeomAction( GEOMOp::OpTolerance, "TOLERANCE" ); createGeomAction( GEOMOp::OpWhatIs, "WHAT_IS" ); @@ -1310,6 +1312,8 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpAngle, dimId, -1 ); createMenu( GEOMOp::OpManageDimensions, dimId, -1 ); + createMenu( GEOMOp::OpAnnotation, measurId, -1 ); + createMenu( separator(), measurId, -1 ); createMenu( GEOMOp::OpTolerance, measurId, -1 ); createMenu( separator(), measurId, -1 ); @@ -1466,6 +1470,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpBoundingBox, measureTbId ); createTool( GEOMOp::OpMinDistance, measureTbId ); createTool( GEOMOp::OpAngle, measureTbId ); + createTool( GEOMOp::OpAnnotation, measureTbId ); createTool( GEOMOp::OpTolerance , measureTbId ); createTool( separator(), measureTbId ); createTool( GEOMOp::OpFreeBoundaries, measureTbId ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index cc44ca9a9..b045f5c15 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -207,6 +207,8 @@ namespace GEOMOp { #ifndef DISABLE_PLOT2DVIEWER OpShapeStatistics = 5019, // MENU MEASURES - SHAPE STATISTICS #endif + OpAnnotation = 5020, // MENU MEASURES - ANNOTATION + OpEditAnnotation = 5021, // POPUP MENU - EDIT ANNOTATION // GroupGUI --------------------//-------------------------------- OpGroupCreate = 6000, // MENU GROUP - CREATE OpGroupEdit = 6001, // MENU GROUP - EDIT diff --git a/src/MeasureGUI/CMakeLists.txt b/src/MeasureGUI/CMakeLists.txt index 5b652b084..a4df31875 100755 --- a/src/MeasureGUI/CMakeLists.txt +++ b/src/MeasureGUI/CMakeLists.txt @@ -88,6 +88,7 @@ SET(MeasureGUI_HEADERS MeasureGUI_InertiaDlg.h MeasureGUI_BndBoxDlg.h MeasureGUI_DistanceDlg.h + MeasureGUI_AnnotationDlg.h MeasureGUI_AngleDlg.h MeasureGUI_MaxToleranceDlg.h MeasureGUI_WhatisDlg.h @@ -116,6 +117,7 @@ SET(_moc_HEADERS MeasureGUI_InertiaDlg.h MeasureGUI_BndBoxDlg.h MeasureGUI_DistanceDlg.h + MeasureGUI_AnnotationDlg.h MeasureGUI_AngleDlg.h MeasureGUI_MaxToleranceDlg.h MeasureGUI_WhatisDlg.h @@ -154,6 +156,7 @@ SET(MeasureGUI_SOURCES MeasureGUI_InertiaDlg.cxx MeasureGUI_BndBoxDlg.cxx MeasureGUI_DistanceDlg.cxx + MeasureGUI_AnnotationDlg.cxx MeasureGUI_AngleDlg.cxx MeasureGUI_MaxToleranceDlg.cxx MeasureGUI_WhatisDlg.cxx diff --git a/src/MeasureGUI/MeasureGUI.cxx b/src/MeasureGUI/MeasureGUI.cxx index 38a6f3be7..f4ec47d14 100644 --- a/src/MeasureGUI/MeasureGUI.cxx +++ b/src/MeasureGUI/MeasureGUI.cxx @@ -44,6 +44,7 @@ #include "MeasureGUI_BndBoxDlg.h" // Method BNDBOX #include "MeasureGUI_DistanceDlg.h" // Method DISTANCE #include "MeasureGUI_AngleDlg.h" // Method ANGLE +#include "MeasureGUI_AnnotationDlg.h" // Method ANNOTATION #include "MeasureGUI_MaxToleranceDlg.h" // Method MAXTOLERANCE #include "MeasureGUI_WhatisDlg.h" // Method WHATIS #include "MeasureGUI_CheckShapeDlg.h" // Method CHECKSHAPE @@ -111,6 +112,14 @@ bool MeasureGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpAngle: dlg = new MeasureGUI_AngleDlg( getGeometryGUI(), parent ); break; // ANGLE + case GEOMOp::OpAnnotation: { + dlg = new MeasureGUI_AnnotationDlg( getGeometryGUI(), true, parent ); + } // ANNOTATION + break; + case GEOMOp::OpEditAnnotation: { + dlg = new MeasureGUI_AnnotationDlg( getGeometryGUI(), false, parent ); + } // ANNOTATION + break; case GEOMOp::OpTolerance: dlg = new MeasureGUI_MaxToleranceDlg( getGeometryGUI(), parent ); break; // MAXTOLERANCE diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx new file mode 100644 index 000000000..1cb4d3301 --- /dev/null +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx @@ -0,0 +1,1439 @@ +// 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 + +#include "MeasureGUI_AnnotationDlg.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#ifdef max +#undef max +#endif + +//======================================================================= +//function : MeasureGUI_AnnotationDlg +//purpose : +//======================================================================= + +MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg( GeometryGUI* theGeometryGUI, + const bool theIsCreate, QWidget* parent, bool modal, Qt::WindowFlags fl ) +: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ), + myIsCreation( theIsCreate ) +//myCurStepID( stepID ), +//myCurStepTable( NULL ), +//myIsHiddenMain( false ) +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle( + myIsCreation ? + tr("CREATE_ANNOTATION_TITLE") : + tr("EDIT_ANNOTATION_TITLE")); + + // Shape type button group + mainFrame()->GroupConstructors->hide(); + + // Field name + mainFrame()->GroupBoxName->setTitle(tr("ANNOTATION_NAME")); + + // Field properties + + QGroupBox* propGroup = new QGroupBox(tr("PROPERTIES"), centralWidget()); + QGridLayout* propLayout = new QGridLayout(propGroup); + propLayout->setMargin(9); + propLayout->setSpacing(6); + + QLabel* textLabel = new QLabel(tr("TEXT"), propGroup); + myTextEdit = new QLineEdit(propGroup); + propLayout->addWidget(textLabel, 0, 0); + propLayout->addWidget(myTextEdit, 0, 1, 1, 2); + + // shape + QLabel* shapeLabel = new QLabel(tr("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")); + myTypeCombo->setCurrentIndex( 0 ); // double +/* + // dimension + QLabel* dimLabel = new QLabel( tr("SHAPE_TYPE"), propGroup ); + myDimCombo = new QComboBox( propGroup ); + + // nb components + QLabel* nbCompsLabel = new QLabel( tr("NB_COMPS"), propGroup ); + myNbCompsSpin = new SalomeApp_IntSpinBox( 1, 1000, 1, propGroup, true, true ); + myNbCompsSpin->setValue( 1 );*/ + propLayout->addWidget(shapeLabel, 1, 0); + propLayout->addWidget(myShapeSelBtn, 1, 1); + propLayout->addWidget(myShapeName, 1, 2); + propLayout->addWidget(typeLabel, 2, 0, 1, 2); + propLayout->addWidget(myTypeCombo, 2, 2); + /*propLayout->addWidget(dimLabel, 2, 0, 1, 2); + propLayout->addWidget(myDimCombo, 2, 2); + propLayout->addWidget(nbCompsLabel, 3, 0, 1, 2); + propLayout->addWidget(myNbCompsSpin, 3, 2); + // propLayout->addWidget(shapeLabel, 0, 0); + // propLayout->addWidget(myShapeName, 0, 1); + // propLayout->addWidget(typeLabel, 1, 0); + // propLayout->addWidget(myTypeCombo, 1, 1); + // propLayout->addWidget(dimLabel, 2, 0); + // propLayout->addWidget(myDimCombo, 2, 1); + // propLayout->addWidget(nbCompsLabel, 3, 0); + // propLayout->addWidget(myNbCompsSpin, 3, 1); + */ + propLayout->setColumnStretch(2, 5); + + QLabel* shapeTypeLabel = new QLabel( tr("SUB_SHAPE"), propGroup ); + mySubShapeTypeCombo = new QComboBox( propGroup ); + QMap aShapeTypes; + aShapeTypes["NONE"] = TopAbs_SHAPE; + aShapeTypes["VERTEX"] = TopAbs_VERTEX; + aShapeTypes["EDGE"] = TopAbs_EDGE; + aShapeTypes["FACE"] = TopAbs_FACE; + aShapeTypes["SOLID"] = TopAbs_SOLID; + QMap::const_iterator anIt = aShapeTypes.begin(), + aLast = aShapeTypes.end(); + for ( ; anIt != aLast; anIt++) + mySubShapeTypeCombo->addItem( anIt.key(), anIt.value()); + mySubShapeTypeCombo->setCurrentIndex( 0 ); // VERTEX + + 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 values + /* + QGroupBox* valsGroup = new QGroupBox(tr("VALUES"), centralWidget()); + QGridLayout* valsLayout = new QGridLayout(valsGroup); + valsLayout->setMargin(9); + valsLayout->setSpacing(6); + + // value table + mySwitchTableWdg = new QWidget(valsGroup); + QVBoxLayout* switchTableGrpLayout = new QVBoxLayout(mySwitchTableWdg); + switchTableGrpLayout->setMargin(0); + switchTableGrpLayout->setSpacing(0); + + // step add/rm controls + QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup ); + QLabel* curStepLbl = new QLabel(tr("STEP"), valsGroup ); + myStepEdit = new QLineEdit( valsGroup ); + myStepsCombo = new QComboBox(valsGroup); + myStepsCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); + myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup ); + + // step browse controls + myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup ); + QLabel* stampLbl = new QLabel(tr("STAMP"), valsGroup ); + myStampSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, valsGroup, true, true); + myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup ); + + valsLayout->addWidget(mySwitchTableWdg, 0, 0, 1, 5); + valsLayout->addWidget(addStepBtn, 1, 0); + valsLayout->addWidget(curStepLbl, 1, 1); + valsLayout->addWidget(myStepEdit, 1, 2); + valsLayout->addWidget(myStepsCombo, 1, 3); + valsLayout->addWidget(myRmStepBtn, 1, 4); + valsLayout->addWidget(myPrevStepBtn, 2, 0); + valsLayout->addWidget(stampLbl, 2, 1); + valsLayout->addWidget(myStampSpin, 2, 2, 1, 2); + valsLayout->addWidget(myNextStepBtn, 2, 4); + + valsLayout->setColumnStretch(3, 5); + valsLayout->setRowStretch (0, 5); + */ + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); + layout->setSpacing(6); + layout->addWidget(propGroup); + //layout->addWidget(valsGroup); + + setHelpFileName("geom_field_page.html"); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, + SLOT(SelectionIntoArgument())); + /* + connect(myPrevStepBtn, SIGNAL(clicked()), this, SLOT( onPrevStep() )); + connect(myNextStepBtn, SIGNAL(clicked()), this, SLOT( onNextStep() )); + connect(addStepBtn, SIGNAL(clicked()), this, SLOT( onAddStep() )); + connect(myRmStepBtn, SIGNAL(clicked()), this, SLOT( onRmStep() )); + connect(myStampSpin, SIGNAL(valueChanged(int)), this, SLOT( onStampChange() )); + connect(myStepsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( showCurStep() )); + connect(myStepsCombo, SIGNAL(activated(int)), this, SLOT( showCurStep() )); + */ + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + Init(); + //updateState(); +} + +//======================================================================= +//function : ~MeasureGUI_AnnotationDlg +//purpose : +//======================================================================= + +MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() { + /*GEOM_Displayer* aDisplayer = getDisplayer(); + if (myIsHiddenMain) { + aDisplayer->Display(myShape); + myIsHiddenMain = false; + } + // if ( !myAnnotation->_is_nil()) + // aDisplayer->Display(myAnnotation); + + QListIterator anIter( myHiddenFieldStepIds ); + while( anIter.hasNext() ) + { + const int aStepId = anIter.next(); + GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( aStepId ); + if( !step->_is_nil() ) + aDisplayer->Display( step, false ); + } + aDisplayer->UpdateViewer();*/ +} + +bool MeasureGUI_AnnotationDlg::isCreateOperation() const { + return myIsCreation; +} + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void MeasureGUI_AnnotationDlg::Init() { + /*myDmMode = -1; + myHiddenFieldStepIds.clear(); + myStepsCombo->clear(); + */ + if (myIsCreation/* || myAnnotation->_is_nil()*/) { + //myIsCreation = true; + /*myStepTables.clear(); + if ( myCurStepTable ) + myCurStepTable->hide(); + myCurStepTable = NULL; + myCurStepID = 0; + */ + initName(tr("ANNOTATION_PREFIX")); + //myStampSpin->setValue(0); + + + myAnnotationProperties.Position = gp_Pnt(50, 50, 50); + gp_Pnt Attach; + + SelectionIntoArgument(); + + //onAddStep(); + + mySelectionModes.clear(); + mySelectionModes.append(TopAbs_SHAPE); + + connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(mySubShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(myTextEdit, SIGNAL(currentIndexChanged(int)), this, SLOT( onTextChange())); + connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onTypeChange())); + connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onSubShapeTypeChange())); + + + /* connect(myDimCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onDimChange())); + connect(myNbCompsSpin, SIGNAL(valueChanged(int)), this, SLOT( onNbCompsChange()));*/ + + } else // edition + { + /*// 1) get and sort step IDs + // 2) hide all displayed field steps' presentations + GEOM_Displayer* aDisplayer = getDisplayer(); + GEOM::ListOfLong_var stepIDs = myAnnotation->GetSteps(); + size_t i; + QList< int > stepsList; + for ( i = 0; i < stepIDs->length(); ++i ) + { + int aStepId = stepIDs[i]; + stepsList.push_back( aStepId ); + GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( aStepId ); + if( !step->_is_nil() ) + { + QString anEntry( step->GetStudyEntry() ); + if( aDisplayer->IsDisplayed( anEntry ) ) + { + aDisplayer->Erase( step, false, false ); + myHiddenFieldStepIds << aStepId; + } + } + } + qSort( stepsList.begin(), stepsList.end() ); + + myIsCreation = false; + + CORBA::String_var fName = "Annotation_name";//myShape->GetName(); + myMainFrame->ResultName->setText( fName.in() ); + + //myShape = myAnnotation->GetShape(); + CORBA::String_var sName; + if ( !myShape->_is_nil() ) + sName = myShape->GetName(); + myShapeName->setText( sName.in() ? sName.in() : ""); + + myTypeCombo->setCurrentIndex( myAnnotation->GetDataType() ); + + updateDims( myAnnotation->GetDimension() ); + updateShapeIDs(); + + GEOM::string_array_var compNames = myAnnotation->GetComponents(); + myNbCompsSpin->setValue( compNames->length() ); + + myShapeSelBtn->setEnabled( false ); + myShapeName->setEnabled( false ); + + myTypeCombo->setEnabled( false ); + myDimCombo->setEnabled( false ); + myNbCompsSpin->setEnabled( false ); + + myStepsCombo->blockSignals( true ); + for ( i = 0; i < stepIDs->length(); ++i ) + { + myStepsCombo->insertItem( i, QString::number( stepsList[i] )); + if ( myCurStepID == stepsList[i] ) + myStepsCombo->setCurrentIndex( i ); + } + // if ( myStepsCombo->count() == 0 ) + // myStepsCombo->insertItem( 0, QString::number( myCurStepID )); + myStepsCombo->blockSignals( false ); + + showCurStep();*/ + //activateSelection(); + } + //GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth ); +} + +//================================================================================= +// function : getShapeType() +// purpose : +//================================================================================= +TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const +{ + return (TopAbs_ShapeEnum)mySubShapeTypeCombo->itemData( mySubShapeTypeCombo->currentIndex() ).toInt(); +} + +//================================================================================= +// function : enterEvent() +// purpose : +//================================================================================= +/*void MeasureGUI_AnnotationDlg::enterEvent(QEvent* e) + { + //if (!buttonCancel()->isEnabled()) + // ActivateThisDialog(); + }*/ + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void MeasureGUI_AnnotationDlg::ClickOnOk() +{ + setIsApplyAndClose(true); + if (ClickOnApply()) + ClickOnCancel(); + setIsApplyAndClose(false); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool MeasureGUI_AnnotationDlg::ClickOnApply() +{ + if(!isApplyAndClose()) { + setIsDisableBrowsing( true ); + setIsDisplayResult( false ); + } + + QString msg; + if ( !isValid( msg ) ) { + showError( msg ); + return false; + } + SUIT_OverrideCursor wc; + SUIT_Session::session()->activeApplication()->putInfo( "" ); + + try + { + if ( openCommand() ) + if (!execute (/*isApplyAndClose()*/)) + { + abortCommand(); + showError(); + return false; + } + } + catch( const SALOME::SALOME_Exception& e ) { + SalomeApp_Tools::QtCatchCorbaException( e ); + abortCommand(); + return false; + } + commitCommand(); + + if(!isApplyAndClose()) { + setIsDisableBrowsing( false ); + setIsDisplayResult( true ); + } + + /*if ( myIsCreation ) + { + myAnnotation = GEOM::GEOM_Field::_nil(); + if ( !isApplyAndClose() ) + Init(); + }*/ + return true; + } + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +/*void MeasureGUI_AnnotationDlg::ActivateThisDialog() + { + GEOMBase_Skeleton::ActivateThisDialog(); + + //connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + // this, SLOT(SelectionIntoArgument())); + + //activateSelection(); + }*/ + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() +{ + QPushButton* aSelectButton = (QPushButton*)sender(); + QPushButton* anOtherButton = 0; + if (aSelectButton == myShapeSelBtn) { + myEditCurrentArgument = myShapeName; + anOtherButton = mySubShapeSelBtn; + } + else if (aSelectButton == mySubShapeSelBtn) { + myEditCurrentArgument = mySubShapeName; + anOtherButton = myShapeSelBtn; + } + myEditCurrentArgument->setFocus(); + + if ( aSelectButton->isChecked() ) + anOtherButton->setDown(false); + + SelectionIntoArgument(); +} + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection has changed +//================================================================================= +void MeasureGUI_AnnotationDlg::SelectionIntoArgument() +{ + if ( myIsCreation ) + { + GEOM::GeomObjPtr anObj = getSelected( mySelectionModes ); + + QString aName = GEOMBase::GetName( anObj.get() ); + myEditCurrentArgument->setText( aName ); + + gp_Pnt anAttachPoint; + int aSubShapeIndex = -1; + if ( myEditCurrentArgument == myShapeName ) { // Selection of a shape is active + if ( myShape->_is_nil() ) + myShape = GEOM::GEOM_Object::_nil(); + else + myShape = anObj; + anAttachPoint = gp_Pnt(100, 100, 100); + } + else if ( myEditCurrentArgument == myShapeName ) { + if ( !myShape->_is_nil() ) { + TopTools_IndexedMapOfShape aMainMap; + TopoDS_Shape aMainShape; + GEOMBase::GetShape(myShape.get(), aMainShape); + TopExp::MapShapes(aMainShape, aMainMap); + + TopExp_Explorer anExp (aMainShape, getShapeType()); + bool isShowWarning = true; + + for (; anExp.More() && aSubShapeIndex < 0; anExp.Next()) { + TopoDS_Shape aSubShape = anExp.Current(); + int anIndex = aMainMap.FindIndex(aSubShape); + if (anIndex >= 0) + aSubShapeIndex = anIndex; + } + anAttachPoint = gp_Pnt(150, 150, 150); + } + } + myAnnotationProperties.Attach = anAttachPoint; + + /*if (myShape->_is_nil()) { + // myShapeName->setText(""); + // myShape = GEOM::GEOM_Object::_nil(); + + + this->myCurrentSelector->clear(); + mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr(); + + //if ( GEOMBase::IsShape(anObj) && anObj->IsMainShape() ) { + // if (myIsHiddenMain) { + // GEOM_Displayer* aDisplayer = getDisplayer(); + // aDisplayer->Display(myShape); + // myIsHiddenMain = false; + // } + myShapeName->setText(GEOMBase::GetName(anObj)); + if (!anObj->_is_nil() /*&& !anObj->IsSame( myShape )*+/) { + myShape = anObj; + //myShapeMap.Clear(); + //myEditCurrentArgument = 0; + + // re-fill myDimCombo + //const int curDim = getDim(); + //updateDims( -100 ); + + // update table + //onDimChange(); + //} + } + }*/ + /*else { + if (myIsHiddenMain) { + GEOM_Displayer* aDisplayer = getDisplayer(); + aDisplayer->Display(myShape); + myIsHiddenMain = false; + } + }*/ + } + /*else // select rows of a table according to shape selection + { + /* if ( !myCurStepTable ) + return; + + bool isSignalsBlocked = myCurStepTable->signalsBlocked(); + myCurStepTable->blockSignals(true); + + QList< int > rowsToSelect; + TColStd_IndexedMapOfInteger aMapIndex; + if ( getSelectedSubshapes(aMapIndex )) + for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) { + const int shapeID = aMapIndex( ii ); + for (int row = 0, n = myShapeIDs.size(); row < n; row++) + if ( myShapeIDs[row] == shapeID ) { + rowsToSelect.push_back( row ); + break; + } + } + myCurStepTable->selectRows( rowsToSelect ); + + myCurStepTable->blockSignals(isSignalsBlocked);*+/ + }*/ +} +/* + //================================================================================= + // function : onDimChange() + // purpose : update dialog at change of dimension + //================================================================================= + void MeasureGUI_AnnotationDlg::onDimChange() + { + // get order of sub-shapes - myShapeIDs + updateShapeIDs(); + + // update size of tables + const int nbRows = myShapeIDs.size(); + QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText(); + QMap< int, StepTable* >::iterator tblIt = myStepTables.begin(); + for ( ; tblIt != myStepTables.end(); ++tblIt ) + if ( tblIt.value() ) + tblIt.value()->setDim( nbRows, subName ); + + activateSelection(); + } + + //======================================================================= + //function : onNbCompsChange + //purpose : + //======================================================================= + + void MeasureGUI_AnnotationDlg::onNbCompsChange() + { + QMap< int, StepTable* >::iterator tblIt = myStepTables.begin(); + for ( ; tblIt != myStepTables.end(); ++tblIt ) + if ( tblIt.value() ) + tblIt.value()->setNbComps( getNbComps() ); + } +*/ +//======================================================================= +//function : onTextChange +//purpose : +//======================================================================= +void MeasureGUI_AnnotationDlg::onTextChange() +{ + myAnnotationProperties.Text = myTextEdit->text(); + processPreview(); +} + +//======================================================================= +//function : onTypeChange +//purpose : +//======================================================================= +void MeasureGUI_AnnotationDlg::onTypeChange() +{ + myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1; + processPreview(); +} + +//======================================================================= +//function : onSubShapeTypeChange +//purpose : +//======================================================================= +void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() +{ + TopAbs_ShapeEnum aShapeType = getShapeType(); + myAnnotationProperties.ShapeType = aShapeType; + + processPreview(); +} + + /* + //================================================================================= + // function : onPrevStep() + // purpose : + //================================================================================= + void MeasureGUI_AnnotationDlg::onPrevStep() + { + int i = myStepsCombo->currentIndex(); + if ( i > 0 ) + { + myStepsCombo->setCurrentIndex( i-1 ); + showCurStep(); + } + } + + //================================================================================= + // function : onNextStep() + // purpose : + //================================================================================= + void MeasureGUI_AnnotationDlg::onNextStep() + { + int i = myStepsCombo->currentIndex(); + if ( i+1 < myStepsCombo->count() ) + { + myStepsCombo->setCurrentIndex( i+1 ); + showCurStep(); + } + } + + static int findInCombo( QComboBox* where, int what, bool& ok ) + { + int idx = 0; + ok = false; + + for ( ; idx < where->count() && !ok; idx++ ) { + int step = where->itemText( idx ).toInt(); + if ( step == what ) { + ok = true; + } + else if ( step > what ) + break; + } + + return idx; + } + + //======================================================================= + //function : onAddStep + //purpose : + //======================================================================= + void MeasureGUI_AnnotationDlg::onAddStep() + { + int step = 0; + + if ( !myStepEdit->text().isEmpty() ) + step = myStepEdit->text().toInt(); + bool ok = false; + int idx = findInCombo( myStepsCombo, step, ok ); + + if ( ok ) { + SUIT_MessageBox::critical(this, QObject::tr("ERR_ERROR"), + tr("ERR_STEP_EXISTS")); + return; + } + + myStepsCombo->insertItem( idx, QString::number( step )); + myStepsCombo->setCurrentIndex( idx ); + myRemovedSteps.remove( getCurStepID() ); + //showCurStep(); + } + + //======================================================================= + //function : onRmStep + //purpose : + //======================================================================= + void MeasureGUI_AnnotationDlg::onRmStep() + { + if ( myStepsCombo->count() > 1 ) + { + myStepTables.remove( getCurStepID() ); + myRemovedSteps.insert( getCurStepID() ); + if ( myCurStepTable ) + myCurStepTable->hide(); + myCurStepTable = NULL; + myStepsCombo->removeItem( myStepsCombo->currentIndex() ); + //showCurStep(); + } + } + + //======================================================================= + //function : onStampChange + //purpose : + //======================================================================= + void MeasureGUI_AnnotationDlg::onStampChange() + { + if ( myCurStepTable ) + myCurStepTable->setStamp( myStampSpin->value() ); + } + + //======================================================================= + //function : showCurStep + //purpose : + //======================================================================= + void MeasureGUI_AnnotationDlg::showCurStep() + { + myCurStepID = getCurStepID(); + myStepEdit->setText(QString::number( myCurStepID )); + + QStringList headers; + if ( myCurStepTable ) + { + if ( myCurStepTable->getStepID() == myCurStepID ) + { + myCurStepTable->show(); + return; + } + else + { + myCurStepTable->hide(); + headers = myCurStepTable->getHeaders(); + myCurStepTable->getStamp(); + } + } + + if ( myStepTables.count ( myCurStepID )) + { + myCurStepTable = myStepTables[ myCurStepID ]; + myCurStepTable->setHeaders( headers ); + } + else + { + // if ( myStepsCombo->count() == 0 ) + // return; // edit a field with no steps + + // get step values + GEOM::GEOM_FieldStep_var stepVar; + if ( !myAnnotation->_is_nil() ) + stepVar = myAnnotation->GetStep( myCurStepID ); + + int nbComps = getNbComps(); + if ( headers.count() == 0 ) + { + headers << tr("SUB_SHAPE_HEADER"); + if ( !myIsCreation && !myAnnotation->_is_nil() ) + { + GEOM::string_array_var compNames = myAnnotation->GetComponents(); + for ( int iC = 0; iC < compNames->length(); ++iC ) + headers << compNames[ iC ].in(); + } + else + { + for ( int iC = 0; iC < nbComps; ++iC ) + headers << QString("Comp %1").arg( iC + 1 ); + } + } + QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText(); + myCurStepTable = new StepTable( myCurStepID, getDataType(), myShapeIDs.size(), + nbComps, subName, headers, stepVar, mySwitchTableWdg ); + myStepTables[ myCurStepID ] = myCurStepTable; + mySwitchTableWdg->layout()->addWidget( myCurStepTable ); + } + myCurStepTable->show(); + myStampSpin->setValue( myCurStepTable->getStamp() ); + + connect(myCurStepTable, SIGNAL(itemSelectionChanged()), this, SLOT( highlightSubShapes() )); + + myPrevStepBtn->setEnabled( myStepsCombo->currentIndex() > 0 ); + myNextStepBtn->setEnabled( myStepsCombo->currentIndex()+1 < myStepsCombo->count() ); + myRmStepBtn->setEnabled( myStepsCombo->count() > 1 ); + } + + //================================================================================= + // function : getSelectedSubshapes + // purpose : + //================================================================================= + int MeasureGUI_AnnotationDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex) + { + theMapIndex.Clear(); + + SalomeApp_Application* app = myGeomGUI->getApp(); + if (!app || myShape->_is_nil()) + return 0; + + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + // try to find out and process the global selection + // (of not published objects and of published sub-shapes) + { + SALOME_ListIteratorOfListIO anIter (aSelList); + for (int i = 0; anIter.More(); anIter.Next(), i++) + { + Handle(SALOME_InteractiveObject) anIObj = anIter.Value(); + QString anEntry = anIObj->getEntry(); + QString str = "_"; + int index = anEntry.lastIndexOf(str); + if (index > 0) // selection among special preview + { + anEntry.remove(0, index+1); + int anIndex = anEntry.toInt(); + if (anIndex) + theMapIndex.Add(anIndex); + } + else // selection among published shapes + { + SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); + if (!appStudy) return 0; + _PTR(Study) aStudy = appStudy->studyDS(); + + _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData())); + GEOM::GEOM_Object_var aGeomObj = + GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); + TopoDS_Shape aShape; + if (GEOMBase::GetShape(aGeomObj, aShape)) { + if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) + { + TopExp_Explorer anExp (aShape, getShapeType()); + for (; anExp.More(); anExp.Next()) { + TopoDS_Shape aSubShape = anExp.Current(); + int anIndex = myShapeMap.FindIndex(aSubShape); + if (anIndex == 0) { + SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"), + tr("WRN_NOT_SUBSHAPE")); + } + theMapIndex.Add(anIndex); + } + } + } + } + } // for aSelList + } + + return theMapIndex.Extent(); + } + + //======================================================================= + //function : getDim + //purpose : + //======================================================================= + int MeasureGUI_AnnotationDlg::getDim() const + { + int i = myDimCombo->currentIndex(); + return ( i < 0 ) ? -1 : myDimCombo->itemData( i ).toInt(); + } + + //======================================================================= + //function : getDataType + //purpose : + //======================================================================= + int MeasureGUI_AnnotationDlg::getDataType() const + { + return myTypeCombo->currentIndex(); + } + + //======================================================================= + //function : getCurStepID + //purpose : + //======================================================================= + int MeasureGUI_AnnotationDlg::getCurStepID() const + { + if ( myStepsCombo->count() > 0 ) + return myStepsCombo->currentText().toInt(); + return myCurStepID; + } + + //======================================================================= + //function : getNbComps + //purpose : + //======================================================================= + int MeasureGUI_AnnotationDlg::getNbComps() const + { + return myNbCompsSpin->value(); + } + + //================================================================================= + // function : updateShapeIDs() + // purpose : update myShapeIDs + //================================================================================= + void MeasureGUI_AnnotationDlg::updateShapeIDs() + { + myShapeIDs.clear(); + //myShapeMap.Clear(); + if ( !myShape->_is_nil() ) + { + TopoDS_Shape aShape = + GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape); + if ( myShapeMap.IsEmpty() ) + TopExp::MapShapes(aShape, myShapeMap); + TopAbs_ShapeEnum shapeType = getShapeType(); + if ( shapeType == TopAbs_SHAPE ) + { + myShapeIDs.push_back( 1 ); + } + else + { + TopTools_IndexedMapOfShape dimSubShapesMap; + TopExp::MapShapes(aShape, shapeType, dimSubShapesMap); + myShapeIDs.resize( dimSubShapesMap.Extent() ); + for ( int i = 1; i <= dimSubShapesMap.Extent(); ++i ) + myShapeIDs[i-1] = myShapeMap.FindIndex( dimSubShapesMap(i) ); + } + } + } + + //======================================================================= + //function : updateDims + //purpose : update myDimCombo + //======================================================================= + void MeasureGUI_AnnotationDlg::updateDims(int curDim) + { + myDimCombo->blockSignals( true ); + myDimCombo->clear(); + TopoDS_Shape aShape = + GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape); + + if ( !aShape.IsNull() ) + { + const char* subNames[4] = { "VERTEX","EDGE","FACE","SOLID" }; + TopExp_Explorer exp; + for ( int dim = 0; dim < 4; ++dim ) + { + exp.Init( aShape, getShapeType(&dim)); + if ( exp.More() && !aShape.IsSame( exp.Current() )) + myDimCombo->insertItem( dim, tr( subNames[dim] ), dim ); + } + myDimCombo->insertItem( 4, tr("WHOLE"), -1 ); + + int idx = myDimCombo->findData( curDim ); + if ( idx != -1 ) + myDimCombo->setCurrentIndex( idx ); + else + myDimCombo->setCurrentIndex( myDimCombo->count()-1-(myDimCombo->count()>1?1:0) ); + } + myDimCombo->blockSignals( false ); + } + + //================================================================================= + // function : activateSelection + // purpose : Activate local selection + //================================================================================= + void MeasureGUI_AnnotationDlg::activateSelection() + { + /* + bool isApply = ((QPushButton*)sender() == buttonApply()); + if(!isApplyAndClose()) + erasePreview(false); + + // local selection + if (!myShape->_is_nil() && + !myEditCurrentArgument && + myShapeIDs.size() > 1 ) // shape type is already choosen by user + { + GEOM_Displayer* aDisplayer = getDisplayer(); + CORBA::String_var aMainEntry = myShape->GetStudyEntry(); + + //display mode for main shape + if ( myDmMode == -1 ) { + SALOME_View* view = GEOM_Displayer::GetActiveView(); + if (view) { + Handle(SALOME_InteractiveObject) io = + new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO"); + if ( view->isVisible( io ) ) { + Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true ); + if(!aSh.IsNull()) { + myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode(); + } + // Hide main shape, if explode on VERTEX + if(getShapeType() != TopAbs_VERTEX) { + aDisplayer->Erase(myShape, false, false); + myIsHiddenMain = true; + } + } + else + myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" ); + } + } + aDisplayer->SetDisplayMode(myDmMode); + + // Mantis issue 0021421: do not hide main shape, if explode on VERTEX + if (getShapeType() == TopAbs_VERTEX) { + if (myIsHiddenMain) + aDisplayer->Display(myShape); + } + //aDisplayer->Erase(myAnnotation, false, false); ------- NOR YET implemented + + QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editField_color" ); + Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name(); + + if(!isApplyAndClose()) { + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); + if (activeStudy) + aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if (aViewWindow == 0) return; + + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if (aViewManager->getType() != OCCViewer_Viewer::Type() && + aViewManager->getType() != SVTK_Viewer::Type()) + return; + + SUIT_ViewModel* aViewModel = aViewManager->getViewModel(); + SALOME_View* aView = dynamic_cast(aViewModel); + if (aView == 0) return; + + TopoDS_Shape aMainShape = myShapeMap(1); + for ( int i = 0; i < myShapeIDs.size(); ++i ) + { + int index = myShapeIDs[ i ]; + TopoDS_Shape aSubShape = myShapeMap( index ); + QString anEntry = QString( "TEMP_" ) + aMainEntry.in() + QString("_%1").arg(index); + Handle(SALOME_InteractiveObject) io = + new SALOME_InteractiveObject(anEntry.toLatin1(), "GEOM", "TEMP_IO"); + aDisplayer->SetColor( aCol ); + SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView); + if (aPrs) { + displayPreview(aPrs, true, false); // append, do not update + // TODO: map or delete Prs + } + } + aDisplayer->UnsetDisplayMode(); + aDisplayer->UnsetColor(); + aDisplayer->UpdateViewer(); + } + } + + globalSelection(GEOM_ALLSHAPES); + *+/ + SelectionIntoArgument(); + } + + //================================================================================= + // function : highlightSubShapes + // purpose : select objects corresponding to selected table rows + //================================================================================= + void MeasureGUI_AnnotationDlg::highlightSubShapes() + { + if (CORBA::is_nil(myShape) || !myCurStepTable ) + return; + + TColStd_MapOfInteger anIds; + QList rows = myCurStepTable->selectedRows(); + int ii = 0, nn = rows.count(); + for (; ii < nn; ii++) + { + int shapeNum = rows[ ii ]; + if ( shapeNum < myShapeIDs.size() ) + anIds.Add( myShapeIDs[ shapeNum ]); + } + + SalomeApp_Application* app = myGeomGUI->getApp(); + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + aSelMgr->clearSelected(); + if ( anIds.IsEmpty() ) + return; + + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = app->activeStudy(); + if (activeStudy) + aViewWindow = app->desktop()->activeWindow(); + if (aViewWindow == 0) return; + + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if (aViewManager->getType() != OCCViewer_Viewer::Type() && + aViewManager->getType() != SVTK_Viewer::Type()) + return; + + SUIT_ViewModel* aViewModel = aViewManager->getViewModel(); + SALOME_View* aView = dynamic_cast(aViewModel); + if (aView == 0) return; + + // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects() + + OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); + AIS_ListOfInteractive List; + //ic->DisplayedObjects(List); + ic->ObjectsInside(List); // Mantis issue 0021367 + + SALOME_ListIO aSelList; + + // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape + GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId()); + QMap childsMap; + SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); + if (appStudy) { + _PTR(Study) aStudy = appStudy->studyDS(); + CORBA::String_var aMainEntry = myShape->GetStudyEntry(); + _PTR(SObject) aSObj = aStudy->FindObjectID( aMainEntry.in() ); + _PTR(ChildIterator) anIt = aStudy->NewChildIterator(aSObj); + for (anIt->InitEx(true); anIt->More(); anIt->Next()) { + GEOM::GEOM_Object_var aChild = + GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value())); + if (!CORBA::is_nil(aChild)) { + int index = aLocOp->GetSubShapeIndex(myShape, aChild); + if ( anIds.Contains( index )) { + CORBA::String_var aChildEntry = aChild->GetStudyEntry(); + //childsMap.insert(index, aChildEntry.in()); + Handle(SALOME_InteractiveObject) tmpIO = + new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO"); + aSelList.Append(tmpIO); + } + } + } + } + + AIS_ListIteratorOfListOfInteractive ite (List); + for (; ite.More(); ite.Next()) { + if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { + Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); + if (aSh->hasIO()) { + Handle(SALOME_InteractiveObject) anIO = aSh->getIO(); + QString anEntry = anIO->getEntry(); + int index = anEntry.lastIndexOf("_"); + anEntry.remove(0, index+1); + int anIndex = anEntry.toInt(); + if (anIds.Contains(anIndex)) { + aSelList.Append(anIO); + // if (childsMap.contains (anIndex)) { + // Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO"); + // aSelList.Append(tmpIO); + // } + } + } + } + } + aSelMgr->setSelectedObjects(aSelList); + } + */ +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +/*GEOM::GEOM_IOperations_ptr MeasureGUI_AnnotationDlg::createOperation() + { + return getGeomEngine()->GetIAnnotationOperations(getStudyId()); + }*/ + +#define RETURN_WITH_MSG(a, b) \ + if ((a)) { \ + theMessage += (b); \ + return false; \ + } + +//================================================================================= +// function : isValid() +// purpose : Verify validity of input data +//================================================================================= +bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) { + SalomeApp_Study* study = getStudy(); + RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY")) + RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(), + tr("GEOM_STUDY_LOCKED")) + + if (myIsCreation) { + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_SHAPE")) + } + else { + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) + } + + if (getShapeType() != TopAbs_SHAPE) { + if (myIsCreation) { + //RETURN_WITH_MSG(myAnnotationProperties.SubShapeId >= 0, tr("NO_SUB_SHAPE")) + } + else { + //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) + } + } + + //QString aName = getNewObjectName().trimmed(); + //RETURN_WITH_MSG (aName.isEmpty(), tr("EMPTY_NAME")) + + //RETURN_WITH_MSG ( !myCurStepTable, tr("NO_VALUES")) + return true; +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool MeasureGUI_AnnotationDlg::execute() { + QString anError; + if (!isValid(anError)) + return false; + + Handle (GEOM_Annotation) + aPresentation = new GEOM_Annotation(); + + 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 = + SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + SOCC_Prs* aPrs = + dynamic_cast(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( + 0)); + + if (aPrs) + aPrs->AddObject(aPresentation); + GEOMBase_Helper::displayPreview(aPrs, false, true); + + /*SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( getStudy()->studyDS() ); + SALOMEDS::StudyBuilder_var aBuilder = aStudyDS->NewBuilder(); + + QString aName = getNewObjectName().trimmed(); + QStringList anEntryList; + + if ( myAnnotation->_is_nil() ) // create field + { + /*QStringList columnNames = myCurStepTable->getHeaders(); + int nbComps = columnNames.count() - 1; + GEOM::string_array_var compNames = new GEOM::string_array(); + compNames->length( nbComps ); + for ( int iC = 0; iC < nbComps; ++iC ) + compNames[ iC ] = columnNames[ iC+1 ].toLatin1().constData(); + *+/ + GEOM::GEOM_IFieldOperations_var anOper = GEOM::GEOM_IFieldOperations::_narrow(getOperation()); + myAnnotation = anOper->CreateField( myShape, + aName.toLatin1().constData()/*, + GEOM::field_data_type( getDataType() ), + CORBA::Short( getDim() ), + compNames*+/ ); + if ( myAnnotation->_is_nil() ) + return false; + + SALOMEDS::SObject_wrap aSO = + getGeomEngine()->AddInStudy( aStudyDS, myAnnotation, aName.toLatin1().constData(), myShape ); + if ( !aSO->_is_nil() ) { + myAnnotation->UnRegister(); + CORBA::String_var entry = aSO->GetID(); + anEntryList << entry.in(); + } + } + else // update field name + { + myAnnotation->SetName( aName.toLatin1().constData() ); + + CORBA::String_var entry = myAnnotation->GetStudyEntry(); + if ( entry.in() ) { + SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); + if ( !SO->_is_nil() ) { + aBuilder->SetName(SO, aName.toLatin1().constData()); + } + } + } + + // create / update steps + /*QMap< int, StepTable* >::iterator i_tbl = myStepTables.begin(); + for ( ; i_tbl != myStepTables.end(); ++i_tbl ) + { + StepTable* tbl = i_tbl.value(); + QString stepName = (tr("STEP")+" %1 %2").arg( tbl->getStepID() ).arg( tbl->getStamp() ); + + GEOM::GEOM_FieldStep_var step = tbl->getStep(); + if ( step->_is_nil() ) + { + step = myAnnotation->GetStep( tbl->getStepID() ); + if ( step->_is_nil() ) + { + step = myAnnotation->AddStep( tbl->getStepID(), tbl->getStamp() ); + + SALOMEDS::SObject_wrap aSO = + getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), myAnnotation ); + if ( /*!myIsCreation &&*+/ !aSO->_is_nil() ) { + step->UnRegister(); + CORBA::String_var entry = aSO->GetID(); + anEntryList << entry.in(); + } + } + } + else if ( step->GetStamp() != tbl->getStamp() ) + { + // update a stamp in the object browser + CORBA::String_var entry = step->GetStudyEntry(); + if ( entry.in() ) { + SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); + if ( !SO->_is_nil() ) + aBuilder->SetName( SO, stepName.toLatin1().constData() ); + } + } + + tbl->setValues( step ); + + // update the presentation if it is displayed + CORBA::String_var aStepEntry = step->GetStudyEntry(); + Handle(SALOME_InteractiveObject) aStepIO = + new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" ); + getDisplayer()->Redisplay( aStepIO, false, false ); + }*+/ + getDisplayer()->UpdateViewer(); + + // remove steps + if ( !myIsCreation ) + { + /*QSet< int >::iterator stepID = myRemovedSteps.begin(); + for ( ; stepID != myRemovedSteps.end(); ++stepID ) + { + GEOM::GEOM_FieldStep_var step = myAnnotation->GetStep( *stepID ); + if ( !step->_is_nil() ) + { + CORBA::String_var entry = step->GetStudyEntry(); + myAnnotation->RemoveStep( *stepID ); + + if ( entry.in() ) { + SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() ); + if ( !SO->_is_nil() ) + aBuilder->RemoveObjectWithChildren( SO ); + } + } + }*+/ + } + myRemovedSteps.clear(); + + updateObjBrowser(); + + if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) { + LightApp_Application* aLightApp = dynamic_cast( anApp ); + if( aLightApp && !isDisableBrowsing() && anEntryList.count() ) + { + aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() ); + anApp->putInfo( QObject::tr("GEOM_PRP_DONE") ); + } + } + */ + return true; +} + +//================================================================================= +// function : getSourceObjects +// purpose : virtual method to get source objects +//================================================================================= +/*QList MeasureGUI_AnnotationDlg::getSourceObjects() + { + QList res; + GEOM::GeomObjPtr aGeomObjPtr(myAnnotation->GetShape()); + res << aGeomObjPtr; + return res; + }*/ + diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.h b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h new file mode 100644 index 000000000..1cf0f0a63 --- /dev/null +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.h @@ -0,0 +1,213 @@ +// 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 +// + +// GEOM GEOMGUI : GUI for Geometry component +// File : MeasureGUI_AnnotationDlg.h + +#ifndef MeasureGUI_AnnotationDlg_H +#define MeasureGUI_AnnotationDlg_H + +#include + +//#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +class QGroupBox; +class QLineEdit; +class QPushButton; +class QComboBox; +class SalomeApp_IntSpinBox; + +//================================================================================= +// class : MeasureGUI_AnnotationDlg +// purpose : +//================================================================================= +class MeasureGUI_AnnotationDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + + /*class StepTable; + class IntSpinItem; + class DoubleSpinItem; + class CheckItem; + class Delegate;*/ + +public: + MeasureGUI_AnnotationDlg (GeometryGUI* theGeometryGUI, + const bool theIsCreate, + QWidget* parent=0, + bool modal=false, Qt::WindowFlags fl=0); + ~MeasureGUI_AnnotationDlg(); + +protected: + // redefined from GEOMBase_Helper + //virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid (QString&); + virtual bool execute (); + //virtual QList getSourceObjects(); + +private slots: + void ClickOnOk(); + bool ClickOnApply(); + //void ActivateThisDialog(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); + +/*void onPrevStep(); + void onNextStep(); + void onAddStep(); + void onRmStep(); + void onStampChange(); + void onDimChange();*/ + void onTextChange(); + void onTypeChange(); + void onSubShapeTypeChange(); + +/*void onNbCompsChange(); + void showCurStep(); + void highlightSubShapes(); +*/ +private: + bool isCreateOperation() const; + + void Init(); + //void enterEvent (QEvent*); + //void activateSelection(); + + TopAbs_ShapeEnum getShapeType() const; +/* int getDim() const; + int getDataType() const; + int getCurStepID() const; + int getNbComps() const; + void updateShapeIDs(); + void updateDims(int curDim=-1); + int getSelectedSubshapes (TColStd_IndexedMapOfInteger& map); +*/ +private: + QList mySelectionModes; + GEOMGUI_ShapeAnnotations::ShapeAnnotation myAnnotationProperties; + /// an index of edited annotation in the list shape annotations, -1 in create operation + bool myIsCreation; + GEOM::GeomObjPtr myShape; + /*QVector< int > myShapeIDs; + TopTools_IndexedMapOfShape myShapeMap; + + int myCurStepID; + StepTable* myCurStepTable; + QMap< int, StepTable* > myStepTables; + QSet< int > myRemovedSteps; + + int myDmMode;*/ + //bool myIsHiddenMain; + + // QList myHiddenFieldStepIds; + + QLineEdit* myTextEdit; + + QPushButton* myShapeSelBtn; + QLineEdit* myShapeName; + QComboBox* myTypeCombo; + + QComboBox* mySubShapeTypeCombo; + + QPushButton* mySubShapeSelBtn; + QLineEdit* mySubShapeName; + + /* + QComboBox* myDimCombo; + QPushButton* myPrevStepBtn; + QPushButton* myNextStepBtn; + QPushButton* myRmStepBtn; + + SalomeApp_IntSpinBox* myNbCompsSpin; + QWidget* mySwitchTableWdg; + QComboBox* myStepsCombo; + QLineEdit* myStepEdit; + SalomeApp_IntSpinBox* myStampSpin; +*/ +}; + +/* + Class : MeasureGUI_AnnotationDlg::StepTable + Description : Table widget +*/ + +/*class MeasureGUI_AnnotationDlg::StepTable : public QTableWidget +{ + Q_OBJECT + + int myDataType; + int myStepID; + int myStamp; + GEOM::GEOM_FieldStep_var myStep; + bool myIsChanged; + + QTableWidgetItem * newDefaultItem(); + +public: + StepTable( int stepID, int dataType, int nbRows, int nbColumns, + QString shapeName, QStringList headers, + GEOM::GEOM_FieldStep_ptr stepVar, QWidget* = 0 ); + virtual ~StepTable(); + + QSize minimumSizeHint() const; + + void setEditable( bool, int, int ); + bool isEditable( int, int ) const; + + void setReadOnly( bool ); + bool isReadOnly() const; + + void insertRows( int, int = 1 ); + QString text( int, int ); + + QList selectedRows(); + void selectRows(const QList& rows); + + void setDim( int nbRows, QString shapeName, bool setDefault=true ); + void setNbComps( int nbComps ); + void setDataType( int dataType ); + void setStamp( int stamp ) { myStamp = stamp; } + int getStamp() { return myStamp; } + int getStepID() { return myStepID; } + QStringList getHeaders(); + void setHeaders(const QStringList& headers); + GEOM::GEOM_FieldStep_var getStep() { return myStep; } + void setValues(GEOM::GEOM_FieldStep_var& step); + +public slots: + void setIsChanged() { myIsChanged = true; } + void headerDblClicked( int ); +};*/ + +#endif -- 2.39.2