X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBasicGUI%2FBasicGUI_CurveDlg.cxx;h=2a962c46180c4427c13a3511d6f6c7b382b939b3;hb=643c92eb8f6e84b5643ba9c3bc990110d166f96b;hp=245fe07a86161437f40a355ac2582d91dd0706ac;hpb=d3dd282390888d7dc091ba2c2ffe7923bd7458e6;p=modules%2Fgeom.git diff --git a/src/BasicGUI/BasicGUI_CurveDlg.cxx b/src/BasicGUI/BasicGUI_CurveDlg.cxx index 245fe07a8..2a962c461 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.cxx +++ b/src/BasicGUI/BasicGUI_CurveDlg.cxx @@ -1,76 +1,95 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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. // +// 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 : BasicGUI_CurveDlg.cxx -// Author : Nicolas REJNERI -// Module : GEOM -// $Header$ +// GEOM GEOMGUI : GUI for Geometry component +// File : BasicGUI_CurveDlg.cxx +// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. +// #include "BasicGUI_CurveDlg.h" -#include "QAD_Desktop.h" -#include "QAD_Config.h" -#include "utilities.h" +#include +#include +#include + +#include +#include +#include +#include +#include -#include "SALOME_ListIteratorOfListIO.hxx" -#include "SALOME_ListIO.hxx" +#include +#include -#include "GEOMImpl_Types.hxx" +#include +#include +#include +#include +#include -using namespace std; +#include //================================================================================= // class : BasicGUI_CurveDlg() -// purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the +// purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the // name 'name' and widget flags set to 'f'. // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -BasicGUI_CurveDlg::BasicGUI_CurveDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl) - :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl ) + : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) { - QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE"))); - QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE"))); - QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER"))); + QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) ); + QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) ); + QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) ); + QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT"))); + setWindowTitle( tr( "GEOM_CURVE_TITLE" ) ); - setCaption(tr("GEOM_CURVE_TITLE")); - /***************************************************************/ - RadioButton1->setPixmap( image0 ); - RadioButton2->setPixmap( image3 ); - RadioButton3->setPixmap( image2 ); + mainFrame()->RadioButton1->setIcon( image0 ); + mainFrame()->RadioButton2->setIcon( image3 ); + mainFrame()->RadioButton3->setIcon( image2 ); + + GroupPoints = new DlgRef_1Sel1Check( centralWidget() ); - GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" ); GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) ); - GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") ); - GroupPoints->PushButton1->setPixmap(image1); - + GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) ); + GroupPoints->PushButton1->setIcon( image1 ); + GroupPoints->PushButton1->setDown( true ); + GroupPoints->LineEdit1->setReadOnly( true ); - Layout1->addWidget(GroupPoints, 2, 0); + GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) ); + GroupPoints->CheckButton1->setChecked(false); + GroupPoints->CheckButton1->hide(); + + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + layout->addWidget( GroupPoints ); /***************************************************************/ + setHelpFileName( "create_curve_page.html" ); + Init(); } @@ -96,23 +115,28 @@ void BasicGUI_CurveDlg::Init() myPoints = new GEOM::ListOfGO(); myPoints->length( 0 ); - globalSelection( GEOM_POINT ); + globalSelection(); // close local contexts, if any + localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); /* signals and slots connections */ - connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel())); - connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog())); - connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); - - connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply())); - connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int))); + connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) ); + connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); + + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + + connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) ); + + connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect( GroupPoints->CheckButton1,SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) ); - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ; + connect( myGeomGUI->getApp()->selectionMgr(), + SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); initName( tr( "GEOM_CURVE" ) ); + resize(100,100); ConstructorsClicked( 0 ); } @@ -123,12 +147,21 @@ void BasicGUI_CurveDlg::Init() void BasicGUI_CurveDlg::ConstructorsClicked( int id ) { QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" ); - GroupConstructors->setTitle( aTitle ); - - myPoints = new GEOM::ListOfGO(); - myPoints->length( 0 ); + mainFrame()->GroupConstructors->setTitle( aTitle ); + + if (id == 2) // b-spline + GroupPoints->CheckButton1->show(); + else + GroupPoints->CheckButton1->hide(); + + myPoints = new GEOM::ListOfGO(); + myPoints->length( 0 ); - myEditCurrentArgument->setText(""); + myEditCurrentArgument->setText( "" ); + qApp->processEvents(); + updateGeometry(); + resize( minimumSizeHint() ); + SelectionIntoArgument(); } @@ -138,7 +171,7 @@ void BasicGUI_CurveDlg::ConstructorsClicked( int id ) //================================================================================= void BasicGUI_CurveDlg::SetEditCurrentArgument() { - if ( sender() == GroupPoints->PushButton1 ) + if ( sender() == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1; myEditCurrentArgument->setFocus(); SelectionIntoArgument(); @@ -151,13 +184,22 @@ void BasicGUI_CurveDlg::SetEditCurrentArgument() //================================================================================= void BasicGUI_CurveDlg::LineEditReturnPressed() { - if ( sender() == GroupPoints->LineEdit1 ) + if ( sender() == GroupPoints->LineEdit1 ) { myEditCurrentArgument = GroupPoints->LineEdit1; GEOMBase_Skeleton::LineEditReturnPressed(); } } +//================================================================================= +// function : CheckButtonToggled() +// purpose : +//================================================================================= +void BasicGUI_CurveDlg::CheckButtonToggled() +{ + displayPreview(); +} + //================================================================================= // function : ClickOnOk() // purpose : @@ -178,17 +220,62 @@ bool BasicGUI_CurveDlg::ClickOnApply() return false; initName(); - ConstructorsClicked( getConstructorId() ); + globalSelection(); // close local contexts, if any + localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); return true; } -//======================================================================= -// function : ClickOnCancel() -// purpose : -//======================================================================= -void BasicGUI_CurveDlg::ClickOnCancel() +//================================================================================= +/*! function : isPointInList() + * purpose : Check is point (theObject) in the list \a thePoints. + * \author enk + * \retval -1, if point not in list, else 1 in list + */ +//================================================================================= +static int isPointInList( std::list& thePoints, + GEOM::GEOM_Object_var& theObject ) +{ + int len = thePoints.size(); + + if ( len < 1 ) { + return -1; + } + + for ( std::list::iterator i = thePoints.begin(); i != thePoints.end(); i++ ) { + if ( std::string( (*i)->GetEntry() ) == std::string( theObject->GetEntry() ) ) { + return 1; + } + } + + return -1; +} +//================================================================================= +/*! function : removeUnnecessaryPnt() + * purpose : Remove unnecessary points from list \a theOldPoints + * \author enk + * \li \a theOldPoints - ordered sequence with unnecessary point + * \li \a theNewPoints - not ordered sequence with necessary points + */ +//================================================================================= +static void removeUnnecessaryPnt( std::list& theOldPoints, + GEOM::ListOfGO_var& theNewPoints ) { - GEOMBase_Skeleton::ClickOnCancel(); + std::list objs_to_remove; + for ( std::list::iterator i = theOldPoints.begin(); i != theOldPoints.end(); i++ ) { + bool found = false; + for ( int j = 0; j < theNewPoints->length() && !found ; j++ ) { + if ( std::string( (*i)->GetEntry() ) == std::string( theNewPoints[j]->GetEntry() ) ) { + found = true; + } + } + if ( !found ) { + objs_to_remove.push_back( *i ); + //cout << "removed: " << (*i)->GetEntry() << endl; + } + } + for ( std::list::iterator i = objs_to_remove.begin(); i != objs_to_remove.end(); i++ ) { + theOldPoints.remove( *i ); + } } //================================================================================= @@ -197,27 +284,99 @@ void BasicGUI_CurveDlg::ClickOnCancel() //================================================================================= void BasicGUI_CurveDlg::SelectionIntoArgument() { - myEditCurrentArgument->setText(""); - - Standard_Boolean aRes = Standard_False; - int i = 0; - myPoints->length( mySelection->IObjectCount() ); // this length may be greater than number of objects, - // that will actually be put into myPoints - for ( SALOME_ListIteratorOfListIO anIt( mySelection->StoredIObjects() ); anIt.More(); anIt.Next() ) - { - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes ); - if ( !CORBA::is_nil( aSelectedObject ) && aRes ) - { - //TopoDS_Shape aPointShape; - //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) ) - myPoints[i++] = aSelectedObject; + myEditCurrentArgument->setText( "" ); + + SalomeApp_Application* app = myGeomGUI->getApp(); + SalomeApp_Study* appStudy = dynamic_cast(app->activeStudy()); + _PTR(Study) aDStudy = appStudy->studyDS(); + GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + + int anIndex; + TopoDS_Shape aShape; + TColStd_IndexedMapOfInteger aMapIndexes; + GEOM::GEOM_Object_var anObject; + std::list aList; + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + SALOME_ListIO selected; + aSelMgr->selectedObjects(selected, QString::null, false); + + int IOC = selected.Extent(); + // bool is_append = myPoints->length() < IOC; // if true - add point, else remove + // myPoints->length( IOC ); // this length may be greater than number of objects, + // that will actually be put into myPoints + + for (SALOME_ListIteratorOfListIO anIt (selected); anIt.More(); anIt.Next()) { + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() ); + if (!CORBA::is_nil(aSelectedObject) ) { + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) { + aSelMgr->GetIndexes(anIt.Value(), aMapIndexes); + + if (aMapIndexes.Extent() > 0) { + for (int ii = 1; ii <= aMapIndexes.Extent(); ii++) { + anIndex = aMapIndexes(ii); + QString aName = GEOMBase::GetName( aSelectedObject ); + aName = aName + ":vertex_" + QString::number( anIndex ); + anObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); + //Find Object in study + _PTR(SObject) obj ( aDStudy->FindObjectID( anIt.Value()->getEntry() ) ); + bool inStudy = false; + _PTR(ChildIterator) iit( aDStudy->NewChildIterator( obj ) ); + for (; iit->More() && !inStudy; iit->Next()) { + _PTR(SObject) child( iit->Value() ); + QString aChildName = child->GetName().c_str(); + if ( aChildName == aName ) { + inStudy = true; + CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( iit->Value() ); + anObject = GEOM::GEOM_Object::_narrow( corbaObj ); + } + } + + if ( !inStudy ) + GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( aDStudy ), + anObject, aName.toLatin1().data(), aSelectedObject ); + + int pos = isPointInList( myOrderedSel, anObject ); + if ( pos == -1 ) { + myOrderedSel.push_back( anObject ); + } + // if (!inStudy) + aList.push_back(anObject); + } + } + else { // aMap.Extent() == 0 + if ( aShape.ShapeType() == TopAbs_VERTEX ) { + int pos = isPointInList( myOrderedSel, aSelectedObject ); + if ( pos == -1 ) + myOrderedSel.push_back( aSelectedObject ); + aList.push_back( aSelectedObject ); + } + } + } } } - myPoints->length( i ); // this is the right length, smaller of equal to the previously set - if ( i ) - GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) ); - displayPreview(); + myPoints->length( aList.size() ); + + int k = 0; + for ( std::list::iterator j = aList.begin(); j != aList.end(); j++ ) + myPoints[k++] = *j; + + if ( IOC == 0 ) + myOrderedSel.clear(); + else + removeUnnecessaryPnt( myOrderedSel, myPoints ); + + // if ( myOrderedSel.size() == myPoints->length() ) { + myPoints->length( myOrderedSel.size() ); + k = 0; + for ( std::list::iterator j = myOrderedSel.begin(); j != myOrderedSel.end(); j++ ) + myPoints[k++] = *j; + // } + + if ( myPoints->length() > 0 ) + GroupPoints->LineEdit1->setText( QString::number( myPoints->length() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) ); + + displayPreview(); } @@ -228,11 +387,12 @@ void BasicGUI_CurveDlg::SelectionIntoArgument() void BasicGUI_CurveDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), + this, SLOT( SelectionIntoArgument() ) ); - myGeomGUI->SetState( 0 ); + globalSelection(); // close local contexts, if any + localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); - globalSelection( GEOM_POINT ); ConstructorsClicked( getConstructorId() ); } @@ -242,7 +402,7 @@ void BasicGUI_CurveDlg::ActivateThisDialog() //================================================================================= void BasicGUI_CurveDlg::DeactivateActiveDialog() { - myGeomGUI->SetState( -1 ); + // myGeomGUI->SetState( -1 ); GEOMBase_Skeleton::DeactivateActiveDialog(); } @@ -250,9 +410,9 @@ void BasicGUI_CurveDlg::DeactivateActiveDialog() // function : enterEvent() // purpose : //================================================================================= -void BasicGUI_CurveDlg::enterEvent(QEvent* e) +void BasicGUI_CurveDlg::enterEvent( QEvent* ) { - if ( !GroupConstructors->isEnabled() ) + if ( !mainFrame()->GroupConstructors->isEnabled() ) ActivateThisDialog(); } @@ -262,7 +422,7 @@ void BasicGUI_CurveDlg::enterEvent(QEvent* e) //================================================================================= GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation() { - return getGeomEngine()->GetICurvesOperations( getStudyId() ); + return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() ); } //================================================================================= @@ -284,18 +444,19 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects ) GEOM::GEOM_Object_var anObj; - switch ( getConstructorId() ) - { + GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() ); + + switch ( getConstructorId() ) { case 0 : - anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints ); + anObj = anOper->MakePolyline( myPoints ); res = true; break; case 1 : - anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints ); + anObj = anOper->MakeSplineBezier( myPoints ); res = true; break; case 2 : - anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints ); + anObj = anOper->MakeSplineInterpolation( myPoints, GroupPoints->CheckButton1->isChecked() ); res = true; break; } @@ -305,14 +466,3 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects ) return res; } - -//================================================================================= -// function : closeEvent -// purpose : -//================================================================================= -void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e ) -{ - myGeomGUI->SetState( -1 ); - GEOMBase_Skeleton::closeEvent( e ); -} -