From: mtn Date: Fri, 30 Aug 2013 14:44:52 +0000 (+0000) Subject: Preview was added to Polyline operation X-Git-Tag: BR_hydro_v_0_1~85 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac0a710b8a716d0734c7824e5a15aed5f9965d98;p=modules%2Fhydro.git Preview was added to Polyline operation --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 359b7142..582f61de 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -35,6 +35,7 @@ set(PROJECT_HEADERS HYDROGUI_TwoImagesOp.h HYDROGUI_UpdateFlags.h HYDROGUI_VisualStateOp.h + HYDROGUI_AISCurve.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -71,6 +72,7 @@ set(PROJECT_SOURCES HYDROGUI_TwoImagesDlg.cxx HYDROGUI_TwoImagesOp.cxx HYDROGUI_VisualStateOp.cxx + HYDROGUI_AISCurve.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.cxx b/src/HYDROGUI/HYDROGUI_AISCurve.cxx new file mode 100755 index 00000000..d1e2c7e0 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_AISCurve.cxx @@ -0,0 +1,173 @@ +#include "HYDROGUI_AISCurve.h" +#include "CurveCreator_Curve.hxx" + +#include +#include +#include +#include +#include + +HYDROGUI_AISCurveSection::HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext, + CurveCreator_Curve* theCurve, int theSection) : + myCurve(theCurve), mySection(theSection), myContext(theContext), myIsHL(false) +{ + buildSection(); +} + +HYDROGUI_AISCurveSection::~HYDROGUI_AISCurveSection() +{ + Erase(); + for( int i = 0 ; i < myObjects.size() ; i++ ){ + myObjects[i].Nullify(); + } + myObjects.clear(); +} + +Quantity_Color HYDROGUI_AISCurveSection::getActiveColor() +{ + if( myIsHL ){ + return Quantity_Color( 1., 0., 0., Quantity_TOC_RGB ); + } + return Quantity_Color( 0., 1., 0., Quantity_TOC_RGB ); +} + +void HYDROGUI_AISCurveSection::highlight( bool isHL ) +{ + myIsHL = isHL; + Quantity_Color aColor = getActiveColor(); + for( int i = 0 ; i < myObjects.size() ; i++ ){ + myObjects[i]->SetColor(aColor); + myContext->Display(myObjects[i]); + } +} + +void HYDROGUI_AISCurveSection::Display() +{ + for( int i = 0 ; i < myObjects.size() ; i++ ){ + myContext->Display(myObjects[i]); + } +} + +void HYDROGUI_AISCurveSection::Erase() +{ + for( int i = 0 ; i < myObjects.size() ; i++ ){ + myContext->Erase(myObjects[i]); + } +} + +void HYDROGUI_AISCurveSection::buildSection() +{ + int aSectSize = myCurve->getNbPoints( mySection ); + double anX; + double anY; + double aZ; + int i = 0; + for( ; i < ( aSectSize - 1 ) ; i++ ){ + Handle_AIS_Point anAISPnt = getAISPoint(i); + myObjects.push_back( anAISPnt ); + Handle_AIS_Line aLine = getAISLine( i, i+1 ); + myObjects.push_back( aLine ); + } + if( aSectSize != 0 ){ + Handle_AIS_Point anAISPnt = getAISPoint(i); + myObjects.push_back( anAISPnt ); + if( myCurve->isClosed(mySection) && ( aSectSize > 1 ) ){ + Handle_AIS_Line aLine = getAISLine( i, 0 ); + myObjects.push_back( aLine ); + } + } +} + +Handle_AIS_Point HYDROGUI_AISCurveSection::getAISPoint( int theIndx ) +{ + double anX; + double anY; + double aZ; + getPoint( theIndx, anX, anY, aZ ); + gp_Pnt aPoint( anX, anY, aZ); + AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint)); + return aPnt; +} + +Handle_AIS_Line HYDROGUI_AISCurveSection::getAISLine( int theIndx1, int theIndx2 ) +{ + double anX; + double anY; + double aZ; + getPoint( theIndx1, anX, anY, aZ ); + gp_Pnt aPoint1( anX, anY, aZ); + double anX2; + double anY2; + double aZ2; + getPoint( theIndx2, anX2, anY2, aZ2 ); +//MTN to avoid crash during line construction + if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){ + aZ2 += 1e-7; + } + gp_Pnt aPoint2( anX2, anY2, aZ2 ); + AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) ); + return aLine; +} + +void HYDROGUI_AISCurveSection::getPoint( int theIndx, double& theX, double& theY, double& theZ ) +{ + CurveCreator::Dimension aDim = myCurve->getDimension(); + CurveCreator::Coordinates aCoords = myCurve->getCoordinates( mySection, theIndx ); + theX = aCoords[0]; + theY = aCoords[1]; + theZ = 0.; + if( aDim == CurveCreator::Dim3d ){ + theZ = aCoords[2]; + } +} + +/******************************* HYDROGUI_AISCurve ********************************************/ +HYDROGUI_AISCurve::HYDROGUI_AISCurve( CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ) : + CurveCreator_Listener(), myCurve(theCurve), myContext( theContext ) +{ + myCurve->setListener(this); + buildCurve(); +} + +HYDROGUI_AISCurve::~HYDROGUI_AISCurve(void) +{ +} + +void HYDROGUI_AISCurve::setCurve( CurveCreator_Curve* theCurve ) +{ + myCurve = theCurve; + buildCurve(); +} + +void HYDROGUI_AISCurve::Display() +{ + for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ + myCurveRepresentation[i]->Display(); + } +} + +void HYDROGUI_AISCurve::buildCurve() +{ + for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){ + myCurveRepresentation[i]->Erase(); + delete myCurveRepresentation[i]; + } + myCurveRepresentation.clear(); + for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){ + HYDROGUI_AISCurveSection* aSection = new HYDROGUI_AISCurveSection( myContext, myCurve, i); + myCurveRepresentation.push_back( aSection ); + myCurveRepresentation[i]->Display(); + } +} + +void HYDROGUI_AISCurve::pointInserted( int theSection, int theIndx ) +{ + buildCurve(); +} + +void HYDROGUI_AISCurve::highlightSection( int theSection, bool isHL ) +{ + if( theSection >= myCurveRepresentation.size() ) + return; + myCurveRepresentation[theSection]->highlight(isHL); +} diff --git a/src/HYDROGUI/HYDROGUI_AISCurve.h b/src/HYDROGUI/HYDROGUI_AISCurve.h new file mode 100755 index 00000000..52dd9d2a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_AISCurve.h @@ -0,0 +1,69 @@ +#ifndef HYDROGUI_AIS_CURVE_H +#define HYDROGUI_AIS_CURVE_H + +#include +#include + +#include +#include +#include +#include + +class CurveCreator_Curve; +class AIS_InteractiveObject; +class AIS_Point; +class AIS_Line; + +class HYDROGUI_AISCurveSection +{ +public: + HYDROGUI_AISCurveSection( Handle_AIS_InteractiveContext theContext, + CurveCreator_Curve* theCurve, int theSection ); + virtual ~HYDROGUI_AISCurveSection(); + + void Display(); + void Erase(); + + void highlight( bool isHL ); +protected: + virtual void buildSection(); + void getPoint( int theIndx, double& theX, double& theY, double& theZ ); + Handle_AIS_Point getAISPoint( int theIndx ); + Handle_AIS_Line getAISLine( int theIndx1, int theIndx2 ); + Quantity_Color getActiveColor(); + +private: + CurveCreator_Curve* myCurve; + int mySection; + std::vector< Handle_AIS_InteractiveObject > myObjects; + Handle_AIS_InteractiveContext myContext; + bool myIsHighlight; + bool myIsHL; +}; + +class HYDROGUI_AISCurve : public CurveCreator_Listener +{ +public: + HYDROGUI_AISCurve(CurveCreator_Curve* theCurve, Handle_AIS_InteractiveContext theContext ); + ~HYDROGUI_AISCurve(void); + + void setCurve( CurveCreator_Curve* theCurve ); + + void Display(); + + virtual void pointInserted( int theSection, int theIndx ); + + void highlightSection( int theSection, bool isHL ); + void clearSelection(); + +protected: + virtual void buildCurve(); + Quantity_Color getActiveColor(); + +private: + CurveCreator_Curve* myCurve; + Handle_AIS_InteractiveContext myContext; + std::vector< HYDROGUI_AISCurveSection* > myCurveRepresentation; +}; + +#endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx b/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx index 4cd9b8d6..7deeb6fd 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineDlg.cxx @@ -43,6 +43,8 @@ HYDROGUI_PolylineDlg::HYDROGUI_PolylineDlg( HYDROGUI_Module* theModule, const QS new CurveCreator_Widget( this, NULL); addWidget( myEditorWidget ); + + connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); } HYDROGUI_PolylineDlg::~HYDROGUI_PolylineDlg() @@ -67,3 +69,13 @@ void HYDROGUI_PolylineDlg::setCurve( CurveCreator_Curve* theCurve ) { myEditorWidget->setCurve( theCurve ); } + +QList HYDROGUI_PolylineDlg::getSelectedSections() +{ + return myEditorWidget->getSelectedSections(); +} + +QList< QPair< int, int > > HYDROGUI_PolylineDlg::getSelectedPoints() +{ + return myEditorWidget->getSelectedPoints(); +} diff --git a/src/HYDROGUI/HYDROGUI_PolylineDlg.h b/src/HYDROGUI/HYDROGUI_PolylineDlg.h index ef78c719..059bc2fd 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineDlg.h +++ b/src/HYDROGUI/HYDROGUI_PolylineDlg.h @@ -44,11 +44,15 @@ public: void setCurve( CurveCreator_Curve* theCurve ); void reset(); + + QList getSelectedSections(); + QList< QPair< int, int > > getSelectedPoints(); + protected slots: signals: - void createPreview( QString ); - + void createPreview( QString ); + void selectionChanged(); private: QLineEdit* myName; CurveCreator_Widget* myEditorWidget; diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index 636b6249..52c1509b 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -23,6 +23,10 @@ #include "HYDROGUI_PolylineOp.h" #include "HYDROGUI_PolylineDlg.h" #include "HYDROGUI_Tool.h" +#include "CurveCreator.hxx" +#include "CurveCreator_Curve.hxx" +#include "CurveCreator_CurveEditor.hxx" +#include "HYDROGUI_AISCurve.h" #include #include @@ -30,11 +34,17 @@ #include #include +#include #include +#include +#include + +#include HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit ) -: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL) +: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL), + myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL) { setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) ); } @@ -45,7 +55,9 @@ HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp() HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const { - return new HYDROGUI_PolylineDlg( module(), getName() ); + HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() ); + connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) ); + return aDlg; } bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, @@ -98,6 +110,29 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, return true; } +void HYDROGUI_PolylineOp::onCreatePreview() +{ + LightApp_Application* anApp = module()->getApp(); + + myActiveViewManager = anApp->activeViewManager(); + + myPreviewViewManager = + dynamic_cast( anApp->createViewManager( OCCViewer_Viewer::Type() ) ); + if( myPreviewViewManager ) + { + anApp->selectionMgr()->setEnabled(false); + myPreviewViewManager->setTitle( tr( "CREATE_CURVE" ) ); + OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer(); + aViewer->enableSelection(true); + aViewer->enableMultiselection(true); + Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext(); + + myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx); + + myAISCurve->Display(); + } +} + void HYDROGUI_PolylineOp::startOperation() { CurveCreator_Curve* anOldCurve = myCurve; @@ -142,6 +177,27 @@ void HYDROGUI_PolylineOp::startOperation() aPanel->setPolylineName(aNewName); } aPanel->setCurve(myCurve); + if( myAISCurve ) + myAISCurve->setCurve(myCurve); if( anOldCurve ) delete anOldCurve; + onCreatePreview(); +} + +void HYDROGUI_PolylineOp::onEditorSelectionChanged() +{ + HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel(); + if( !aPanel ) + return; + if( !myCurve ) + return; + if( !myAISCurve ) + return; + QList aSelSections = aPanel->getSelectedSections(); + for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){ + bool aIsHl = false; + if( aSelSections.contains(i) ){ + myAISCurve->highlightSection(i, aIsHl); + } + } } diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.h b/src/HYDROGUI/HYDROGUI_PolylineOp.h index 6ff93f05..2502c970 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.h +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.h @@ -28,6 +28,9 @@ #include class CurveCreator_Curve; +class SUIT_ViewManager; +class OCCViewer_ViewManager; +class HYDROGUI_AISCurve; class HYDROGUI_PolylineOp : public HYDROGUI_Operation { @@ -43,11 +46,21 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); virtual void startOperation(); + + void onCreatePreview(); + +protected slots: + void onEditorSelectionChanged(); private: + SUIT_ViewManager* myActiveViewManager; + + OCCViewer_ViewManager* myPreviewViewManager; + bool myIsEdit; Handle(HYDROData_Polyline) myEditedObject; CurveCreator_Curve* myCurve; + HYDROGUI_AISCurve* myAISCurve; }; #endif