//=======================================================================
void CurveCreator_Widget::reset()
{
+ stopActionMode();
}
void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve )
mySectionView->sectionChanged(mySection);
updateUndoRedo();
onCancelSection();
-
- emit curveModified();
}
void CurveCreator_Widget::onJoin()
if( aNewSectSize != aMainSectSize )
mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );*/
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onRemove()
mySectionView->reset();
updateActionsStates();
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onJoinAll()
mySectionView->reset();
updateActionsStates();
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onUndoSettings()
mySectionView->sectionChanged(aSelSections[i]);
}
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onSetPolyline()
mySectionView->sectionChanged( aSelSections[i] );
}
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onCloseSections()
mySectionView->sectionChanged(aSelSections[i]);
}
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onUncloseSections()
mySectionView->sectionChanged(aSelSections[i]);
}
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::onUndo()
myCurve->undo();
finishCurveModification();
mySectionView->reset();
-
- emit curveModified();
}
void CurveCreator_Widget::onRedo()
myCurve->redo();
finishCurveModification();
mySectionView->reset();
-
- emit curveModified();
}
void CurveCreator_Widget::updateUndoRedo()
if ( theEvent->button() != Qt::LeftButton )
return;
- myPressedX = theEvent->x();
- myPressedY = theEvent->y();
+ // Initialize the starting point
+ myStartPoint.setX( theEvent->x() );
+ myStartPoint.setY( theEvent->y() );
switch( getActionMode() ) {
case ModificationMode: {
* \param theWindow an owner of the signal
* \param theEvent a mouse event
*/
-void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent )
+void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent )
{
+
+ if (theEvent->button() != Qt::LeftButton) return;
+ if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
+
+ // Initialize the ending point
+ myEndPoint.setX( theEvent->x() );
+ myEndPoint.setY( theEvent->y() );
+
+ bool aHasShift = ( theEvent->modifiers() & Qt::ShiftModifier );
+
+ // Highlight detected objects
+ Handle(AIS_InteractiveContext) aCtx = getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
+ if (!aView)
+ return;
+
+ if (!aHasShift)
+ aCtx->ClearCurrents( false );
+
+ Handle(V3d_View) aView3d = aView->getViewPort()->getView();
+ if ( !aView3d.IsNull() )
+ {
+ // Initialize the single selection if start and end points are equal,
+ // otherwise a rectangular selection.
+ if ( myStartPoint == myEndPoint )
+ {
+ aCtx->MoveTo( myEndPoint.x(), myEndPoint.y(), aView3d );
+ if ( aHasShift )
+ aCtx->ShiftSelect();
+ else
+ aCtx->Select();
+ }
+ else
+ {
+ if ( aHasShift )
+ aCtx->ShiftSelect( myStartPoint.x(), myStartPoint.y(), myEndPoint.x(), myEndPoint.y(),
+ aView3d, Standard_False );
+ else
+ aCtx->Select( myStartPoint.x(), myStartPoint.y(), myEndPoint.x(), myEndPoint.y(),
+ aView3d, Standard_False );
+ }
+ }
+ }
+
if ( getActionMode() != ModificationMode )
+ {
+ // Emit selectionChanged() signal
+ getOCCViewer()->performSelectionChanged();
return;
+ }
if ( myDragStarted ) {
bool isDragged = myDragged;
}
else // check whether the segment is clicked an a new point should be added to the segment
{
- int aReleasedX = theEvent->x();
- int aReleasedY = theEvent->y();
- if ( myPressedX == aReleasedX && myPressedY == aReleasedY )
- insertPointToSelectedSegment( aReleasedX, aReleasedY );
+ if ( myStartPoint.x() == myEndPoint.x() && myStartPoint.y() == myEndPoint.y() )
+ insertPointToSelectedSegment( myEndPoint.x(), myStartPoint.y() );
}
// updates the input panel table to show the selected point coordinates
updateLocalPointView();
updateUndoRedo();
-
- emit curveModified();
}
/**
myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
finishCurveModification( aSelPoints );
-
- emit curveModified();
}
/**
}
mySectionView->clearSelection();
updateUndoRedo();
-
- emit curveModified();
}
/**
myCurve->removeSeveralPoints( aPoints );
finishCurveModification( CurveCreator_ICurve::SectionToPointList() );
mySectionView->reset();
-
- emit curveModified();
}
void CurveCreator_Widget::addNewPoint(const CurveCreator::Coordinates& theCoords)
mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
updateActionsStates();
updateUndoRedo();
-
- emit curveModified();
}
void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
finishCurveModification( aSelPoints );
setSelectedPoints();
-
- emit curveModified();
}
void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
myDragged = true;
finishCurveModification( myDragPoints );
-
- emit curveModified();
}
void CurveCreator_Widget::updateLocalPointView()
#include "EntityGUI_PolylineDlg.h"
#include <CurveCreator_Curve.hxx>
+#include <CurveCreator_Displayer.hxx>
#include <CurveCreator_Utils.hxx>
#include <CurveCreator_Widget.h>
#include <DlgRef.h>
#include <BRep_Tool.hxx>
#include <Geom_Surface.hxx>
#include <GeomLib_IsPlanarSurface.hxx>
+#include <Prs3d_LineAspect.hxx>
#include <TopoDS.hxx>
#include <QGroupBox>
myWPlaneLineEdit (0),
myPolylineSelButton (0),
myPolylineEdit (0),
- myEditCurrentArgument (0)
+ myEditCurrentArgument (0),
+ myPreviewManager(0),
+ myPreviewZLayer(-1)
{
QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
myPlnButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
aPlaneLayout->addWidget(myPlnButton, 0, 3);
+ bool isCS = false;
+#ifdef SET_PLANE
+ isCS = true;
+#endif
+ myPlnComboBox->setVisible( isCS );
+ myPlnButton->setVisible( isCS );
+
#ifdef SET_PLANE
QLabel *aPlaneLbl = new QLabel(tr("GEOM_PLANE"), aGroupBox1);
myPolylineSelButton = new QPushButton (aGroupBox1);
myPolylineSelButton->setIcon(image1);
+ myPolylineSelButton->setCheckable(true);
myPolylineEdit = new QLineEdit (aGroupBox1);
myPolylineEdit->setReadOnly(true);
setHelpFileName( "create_polyline_page.html" );
- /* Initialisations */
+ /* Initializations */
Init();
}
//=================================================================================
EntityGUI_PolylineDlg::~EntityGUI_PolylineDlg()
{
- delete myCurve;
+ erasePreview();
}
//=================================================================================
LightApp_SelectionMgr *aSelMgr = myGeomGUI->getApp()->selectionMgr();
myEditorWidget->setOCCViewer(aViewManager ? aViewManager->getOCCViewer() : 0);
+ setPreviewManager( aViewManager );
// Init the list of local coordinate system
gp_Pnt aPnt(0., 0., 0.);
myWPlaneList.push_back(GEOM::GeomObjPtr());
myLCSList.push_back(aLCS);
- connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
- connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
-
#ifdef SET_PLANE
- connect(myPlnSelButton, SIGNAL(clicked()),
- this, SLOT(SetEditCurrentArgument()));
+ connect( myPlnSelButton, SIGNAL(toggled(bool)),
+ this, SLOT(SetEditCurrentArgument(bool)) );
#endif
- connect(myPolylineSelButton, SIGNAL(clicked()),
- this, SLOT(SetEditCurrentArgument()));
- connect(aSelMgr, SIGNAL(currentSelectionChanged()),
- this, SLOT(SelectionIntoArgument()));
- connect(myEditorWidget, SIGNAL(subOperationStarted(QWidget*, bool)),
- this, SLOT(processStartedSubOperation(QWidget*, bool)));
- connect(myEditorWidget, SIGNAL(subOperationFinished(QWidget*)),
- this, SLOT(processFinishedSubOperation(QWidget*)));
- connect(myEditorWidget, SIGNAL(curveModified()),
- this, SLOT(onUpdatePreview()));
+ connect( myPolylineSelButton, SIGNAL(toggled(bool)),
+ this, SLOT(SetEditCurrentArgument(bool)) );
+ connect( aSelMgr, SIGNAL(currentSelectionChanged()),
+ this, SLOT(SelectionIntoArgument()) );
+ connect( myEditorWidget, SIGNAL(subOperationStarted(QWidget*, bool)),
+ this, SLOT(processStartedSubOperation(QWidget*, bool)) );
+ connect( myEditorWidget, SIGNAL(subOperationFinished(QWidget*)),
+ this, SLOT(processFinishedSubOperation(QWidget*)) );
#ifdef SET_PLANE
- connect(myPlnComboBox, SIGNAL(activated(int)),
- this, SLOT(ActivateLocalCS()));
- connect(myPlnButton, SIGNAL(clicked()),
- this, SLOT(ActivateLocalCS()));
+ connect( myPlnComboBox, SIGNAL(activated(int)),
+ this, SLOT(ActivateLocalCS()) );
+ connect( myPlnButton, SIGNAL(clicked()),
+ this, SLOT(ActivateLocalCS()) );
#endif
- connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
- connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
+ connect( buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
+ connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
myAddElementBox->hide();
- myPolylineSelButton->click();
- SelectionIntoArgument();
+
+ // Processing of the selected object
+ myPolylineSelButton->setChecked( true );
+ SelectionIntoArgument( true );
}
//=================================================================================
initName();
+ // Reset actions
+ myEditorWidget->reset();
+
return true;
}
// function : SelectionIntoArgument
// purpose : Called when selection is changed
//=================================================================================
-void EntityGUI_PolylineDlg::SelectionIntoArgument()
+void EntityGUI_PolylineDlg::SelectionIntoArgument( bool isForced )
{
- bool isModified = false;
+ bool isModified = isForced;
GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
TopoDS_Shape aShape;
if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) &&
- !aShape.IsNull()) {
+ !aShape.IsNull())
+ {
QString aName = GEOMBase::GetName(aSelectedObject.get());
- if (myEditCurrentArgument == myPolylineEdit) {
+ if ( myEditCurrentArgument == myPolylineEdit && isCheckToSelect() )
+ {
// Import a curve
CurveCreator_Curve *aNewCurve =
new CurveCreator_Curve(CurveCreator::Dim2d);
#ifdef SET_PLANE
AddLocalCS(aSelectedObject.get(), false, aLocalCS);
myWPlaneLineEdit->clear();
- myPlnSelButton->setDown(false);
+ myPlnSelButton->setChecked(false);
#endif
- myPolylineSelButton->setDown(true);
+ myPolylineSelButton->setChecked(false);
+
+ disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+ myGeomGUI->getApp()->selectionMgr()->clearSelected();
+ connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+ this, SLOT(SelectionIntoArgument()));
} else {
// Does nothing, just clears selection.
delete aNewCurve;
}
+ }
#ifdef SET_PLANE
- } else if (myEditCurrentArgument == myWPlaneLineEdit) {
+ else if ( myEditCurrentArgument == myWPlaneLineEdit && isCheckToSelect() )
+ {
// Import planar face.
if (aShape.ShapeType() == TopAbs_FACE) {
// Check if the face is planar
AddLocalCS(aSelectedObject.get(), true,
WPlaneToLCS(aSelectedObject.get()));
isModified = true;
- myPlnSelButton->setDown(true);
- myPolylineSelButton->setDown(false);
+ myPlnSelButton->setChecked(false);
+ myPolylineSelButton->setChecked(false);
}
}
if (!isModified) {
myEditCurrentArgument->setText(tr("GEOM_SKETCHER_WPLANE"));
}
+ }
#endif
+ }
+ else
+ {
+ if (isForced)
+ {
+#ifdef SET_PLANE
+ myPlnSelButton->setChecked(false);
+#endif
+ myPolylineSelButton->setChecked(false);
}
}
- if (!isModified) {
+ if (!isModified)
+ {
// Does nothing, just clears selection.
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
myGeomGUI->getApp()->selectionMgr()->clearSelected();
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
this, SLOT(SelectionIntoArgument()));
}
+ else
+ displayPreview();
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
-void EntityGUI_PolylineDlg::SetEditCurrentArgument()
+void EntityGUI_PolylineDlg::SetEditCurrentArgument( bool isChecked )
{
- if (sender() == myPlnSelButton) {
+ if (sender() == myPlnSelButton)
+ {
#ifdef SET_PLANE
myEditCurrentArgument = myWPlaneLineEdit;
myEditCurrentArgument->setFocus();
- myPlnSelButton->setDown(true);
- myPolylineSelButton->setDown(false);
+ myPolylineSelButton->blockSignals(true);
+ myPolylineSelButton->setChecked(false);
+ myPolylineSelButton->blockSignals(false);
#endif
- } else if (sender() == myPolylineSelButton) {
+ }
+ else if (sender() == myPolylineSelButton)
+ {
myEditCurrentArgument = myPolylineEdit;
myEditCurrentArgument->setFocus();
#ifdef SET_PLANE
- myPlnSelButton->setDown(false);
+ myPlnSelButton->blockSignals(true);
+ myPlnSelButton->setChecked(false);
+ myPlnSelButton->blockSignals(false);
#endif
- myPolylineSelButton->setDown(true);
}
}
ActivateThisDialog();
}
-//=================================================================================
-// function : onUpdatePreview
-// purpose :
-//=================================================================================
-void EntityGUI_PolylineDlg::onUpdatePreview()
-{
- displayPreview(true);
-}
-
//=================================================================================
// function : ActivateLocalCS
// purpose : Activate & Fit Working plane
{
return myWPlaneList;
}
+
+//=================================================================================
+// function : setPreviewManager ( OCCViewer_ViewManager )
+// purpose : Sets view manager to control the displayed objects.
+//=================================================================================
+void EntityGUI_PolylineDlg::setPreviewManager( OCCViewer_ViewManager* theManager )
+{
+ myPreviewManager = theManager;
+
+ if ( getPreviewManager() )
+ {
+ if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if( !aCtx.IsNull() )
+ {
+ // Add Z layer to show temporary objects
+ int aZLayer = -1;
+ aViewer->getViewer3d()->AddZLayer( aZLayer );
+ setPreviewZLayer( aZLayer );
+ }
+ }
+ }
+}
+
+//=================================================================================
+// function : getPreviewManager()
+// purpose :
+//=================================================================================
+OCCViewer_ViewManager* EntityGUI_PolylineDlg::getPreviewManager()
+{
+ return myPreviewManager;
+}
+
+//=================================================================================
+// function : setPreviewZLayer( theZLayer )
+// purpose : Sets Z layer to show temporary objects.
+//=================================================================================
+void EntityGUI_PolylineDlg::setPreviewZLayer( int theZLayer )
+{
+ if ( theZLayer != myPreviewZLayer )
+ myPreviewZLayer = theZLayer;
+}
+
+//=================================================================================
+// function : getPreviewZLayer()
+// purpose :
+//=================================================================================
+int EntityGUI_PolylineDlg::getPreviewZLayer() const
+{
+ return myPreviewZLayer;
+}
+
+//=================================================================================
+// function : displayPreview()
+// purpose :
+//=================================================================================
+void EntityGUI_PolylineDlg::displayPreview()
+{
+ if ( getPreviewManager() )
+ {
+ if ( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
+ {
+ // Disable changing of OCCViewer's selection to use vertex of curve selection
+ disconnect(getPreviewManager(), SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+ aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx, getPreviewZLayer() );
+ myCurve->setDisplayer( aDisplayer );
+
+ Handle(AIS_InteractiveObject) anAISObj = myCurve->getAISObject( true );
+ aDisplayer->display( anAISObj, true );
+
+ // Set color for temporary AIS_InteractiveObject
+ anAISObj->Attributes()->WireAspect()->SetColor( Quantity_NOC_VIOLET );
+ }
+ }
+ }
+}
+
+//=================================================================================
+// function : erasePreview()
+// purpose :
+//=================================================================================
+void EntityGUI_PolylineDlg::erasePreview()
+{
+ CurveCreator_Displayer* aDisplayer = myCurve ? myCurve->getDisplayer() : 0;
+ if( getPreviewManager() )
+ {
+ if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if( !aCtx.IsNull() && aDisplayer )
+ aDisplayer->eraseAll( true );
+
+ // Enable changing of OCCViewer's selection
+ connect(getPreviewManager(), SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+ aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+ }
+ }
+
+ setPreviewManager( NULL );
+ if ( myCurve )
+ {
+ delete myCurve;
+ myCurve = NULL;
+ }
+}
+
+//=================================================================================
+// function : isCheckToSelect()
+// purpose :
+//=================================================================================
+bool EntityGUI_PolylineDlg::isCheckToSelect()
+{
+#ifdef SET_PLANE
+ return myPlnSelButton->isChecked();
+#endif
+ return myPolylineSelButton->isChecked();
+}