for ( HYDROData_Iterator it( HYDROData_Document::Document( module()->getStudyId() ), objectType() ); it.More(); it.Next() )
{
if ( !objectFilter() || objectFilter()->isOk( it.Current() ) )
+ {
+ theObjects.Append( it.Current() );
aNames.append( it.Current()->GetName() );
+ }
}
return aNames;
}
{
myList->clear();
mySelection.Clear();
+ emit selectionChanged();
}
void HYDROGUI_ObjListBox::setSelectedObjects( const HYDROData_SequenceOfObjects& theObjects )
void HYDROGUI_ObjListBox::OnInclude()
{
Append( HYDROGUI_Tool::GetSelectedObjects( module() ) );
+ emit selectionChanged();
}
void HYDROGUI_ObjListBox::OnExclude()
myList->takeItem( anIndex );
mySelection.Remove( anIndex, anIndex );
}
+ emit selectionChanged();
}
void HYDROGUI_ObjListBox::Append( const HYDROData_SequenceOfObjects& theObjects )
private:
void Init(const QString& theTitle);
+signals:
+ void selectionChanged();
+
private slots:
void OnInclude();
void OnExclude();
#include <HYDROGUI_ObjComboBox.h>
#include <HYDROGUI_ObjListBox.h>
#include <HYDROGUI_Tool.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <CurveCreator_Utils.hxx>
+#include <SUIT_ViewWindow.h>
#include <QtxDoubleSpinBox.h>
#include <QFrame>
#include <QLabel>
#include <QGridLayout>
#include <QTabWidget>
+#include <QMouseEvent>
#include <gp_Pnt2d.hxx>
+const double MIN_COORD = -1000000;
+const double MAX_COORD = 1000000;
+const double STEP = 10;
+
HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle )
-: HYDROGUI_InputPanel( theModule, theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle ), myOCCViewer( 0 )
{
QFrame* aFrame = new QFrame( mainFrame() );
addWidget( aFrame, 1 );
QFrame* aPointPage = new QFrame();
myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage );
myX = new QtxDoubleSpinBox( aPointPage );
+ myX->setRange( MIN_COORD, MAX_COORD );
+ myX->setSingleStep( STEP );
myY = new QtxDoubleSpinBox( aPointPage );
+ myY->setRange( MIN_COORD, MAX_COORD );
+ myY->setSingleStep( STEP );
QGridLayout* aPointPageLayout = new QGridLayout( aPointPage );
aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 );
QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage );
aSplitPageLayout->addWidget( myPolylines, 0, 0 );
myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) );
+
+ connect( myX, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
+ connect( myY, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) );
+ connect( myTab, SIGNAL( currentChanged( int ) ), this, SIGNAL( modeChanged() ) );
+ connect( myMainPolyline1, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+ connect( myMainPolyline2, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+ connect( myToolPolyline, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) );
+ connect( myPolylines, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
}
HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg()
void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection()
{
+ myMainPolyline1->reset();
+ myMainPolyline2->reset();
+ myPolylines->reset();
+
Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() );
if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY )
return;
myMainPolyline2->setObjectName( aName );
myPolylines->setObjectsFromSelection();
}
+
+void HYDROGUI_SplitPolylinesDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
+{
+ if( !theViewer )
+ return;
+
+ myOCCViewer = theViewer;
+ OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>( myOCCViewer->getViewManager() );
+ disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+ this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+ connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
+ this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
+}
+
+void HYDROGUI_SplitPolylinesDlg::onMousePress( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
+{
+ gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), getViewPort()->getView() );
+ myX->setValue( aPnt.X() );
+ myY->setValue( aPnt.Y() );
+}
+
+OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const
+{
+ OCCViewer_ViewPort3d* aViewPort = 0;
+ if ( myOCCViewer )
+ aViewPort = dynamic_cast<OCCViewer_ViewWindow*>( myOCCViewer->getViewManager()->getActiveView() )->getViewPort();
+
+ return aViewPort;
+}
class HYDROGUI_ObjComboBox;
class HYDROGUI_ObjListBox;
class gp_Pnt2d;
+class OCCViewer_Viewer;
+class SUIT_ViewWindow;
+class OCCViewer_ViewPort3d;
class HYDROGUI_SplitPolylinesDlg : public HYDROGUI_InputPanel
{
HYDROData_SequenceOfObjects GetPolylines() const;
void setPolylinesFromSelection();
+ void setOCCViewer( OCCViewer_Viewer* theViewer );
+
+signals:
+ void modeChanged();
+ void pointMoved();
+ void selectionChanged();
+
+private slots:
+ void onMousePress( SUIT_ViewWindow*, QMouseEvent* );
+
+private:
+ OCCViewer_ViewPort3d* getViewPort() const;
private:
QTabWidget* myTab;
HYDROGUI_ObjComboBox* myMainPolyline2;
HYDROGUI_ObjComboBox* myToolPolyline;
HYDROGUI_ObjListBox* myPolylines;
+ OCCViewer_Viewer* myOCCViewer;
};
#endif
#include <HYDROGUI_SplitPolylinesOp.h>
#include <HYDROGUI_SplitPolylinesDlg.h>
+#include <HYDROGUI_Module.h>
#include <HYDROGUI_UpdateFlags.h>
+#include <HYDROGUI_Shape.h>
#include <HYDROData_PolylineOperator.h>
+#include <LightApp_Application.h>
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewManager.h>
#include <gp_Pnt2d.hxx>
+#include <BRepLib_MakeVertex.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Compound.hxx>
HYDROGUI_SplitPolylinesOp::HYDROGUI_SplitPolylinesOp( HYDROGUI_Module* theModule )
-: HYDROGUI_Operation( theModule )
+: HYDROGUI_Operation( theModule ),
+ myPreviewPrs( 0 )
{
setName( tr( "SPLIT_POLYLINES" ) );
}
return;
aPanel->setPolylinesFromSelection();
+ LightApp_Application* anApp = module()->getApp();
+ OCCViewer_ViewManager* aViewManager =
+ dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
+ aPanel->setOCCViewer( aViewManager ? aViewManager->getOCCViewer() : 0 );
+ setPreviewManager( aViewManager );
+ OnUpdatePreview();
}
HYDROGUI_InputPanel* HYDROGUI_SplitPolylinesOp::createInputPanel() const
{
- return new HYDROGUI_SplitPolylinesDlg( module(), getName() );
+ HYDROGUI_SplitPolylinesDlg* aDlg = new HYDROGUI_SplitPolylinesDlg( module(), getName() );
+ connect( aDlg, SIGNAL( pointMoved() ), this, SLOT( OnUpdatePreview() ) );
+ connect( aDlg, SIGNAL( modeChanged() ), this, SLOT( OnUpdatePreview() ) );
+ connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( OnUpdatePreview() ) );
+ return aDlg;
}
bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
return true;
}
+
+void HYDROGUI_SplitPolylinesOp::abortOperation()
+{
+ erasePreview();
+ HYDROGUI_Operation::abortOperation();
+}
+
+void HYDROGUI_SplitPolylinesOp::commitOperation()
+{
+ erasePreview();
+ HYDROGUI_Operation::commitOperation();
+}
+
+void HYDROGUI_SplitPolylinesOp::erasePreview()
+{
+ if( myPreviewPrs )
+ {
+ delete myPreviewPrs;
+ myPreviewPrs = 0;
+ }
+}
+
+void HYDROGUI_SplitPolylinesOp::OnUpdatePreview()
+{
+ OCCViewer_ViewManager* aViewManager = getPreviewManager();
+ if ( aViewManager )
+ {
+ if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ if( !myPreviewPrs )
+ myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+ aCtx->ClearSelected();
+ }
+ }
+ }
+
+ HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast<HYDROGUI_SplitPolylinesDlg*>( inputPanel() );
+ if( myPreviewPrs && aPanel )
+ {
+ BRep_Builder aBB;
+ TopoDS_Compound aCmp;
+ aBB.MakeCompound( aCmp );
+
+ switch( aPanel->GetMode() )
+ {
+ case HYDROGUI_SplitPolylinesDlg::ByPoint:
+ {
+ gp_Pnt2d aPnt = aPanel->GetPoint();
+ TopoDS_Vertex aVertex = BRepLib_MakeVertex( gp_Pnt( aPnt.X(), aPnt.Y(), 0.0 ) );
+ aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
+ aBB.Add( aCmp, aVertex );
+ break;
+ }
+ case HYDROGUI_SplitPolylinesDlg::ByTool:
+ {
+ aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() );
+ aBB.Add( aCmp, aPanel->GetToolPolyline()->GetShape() );
+ break;
+ }
+ case HYDROGUI_SplitPolylinesDlg::Split:
+ {
+ HYDROData_SequenceOfObjects aPolylines = aPanel->GetPolylines();
+ for( int i=aPolylines.Lower(), n=aPolylines.Upper(); i<=n; i++ )
+ {
+ Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( aPolylines.Value( i ) );
+ if( !aPolyline.IsNull() )
+ aBB.Add( aCmp, aPolyline->GetShape() );
+ }
+ break;
+ }
+ }
+
+
+ myPreviewPrs->setShape( aCmp );
+ }
+}
protected:
virtual void startOperation();
+ virtual void abortOperation();
+ virtual void commitOperation();
virtual HYDROGUI_InputPanel* createInputPanel() const;
virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
QStringList& theBrowseObjectsEntries );
+
+ virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; };
+
+protected slots:
+ void OnUpdatePreview();
+ void erasePreview();
+
+private:
+ HYDROGUI_Shape* myPreviewPrs;
};
#endif