The edit operation correction. It is necessary to move any object without preliminary selection. Drag a highlighted object and move it somewhere.
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
- aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+ aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
}
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
- aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+ aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
}
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp)
{
- std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
- aPreviewOp->init(theFeature, aPresentations);
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+ std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+ aPreviewOp->init(theFeature, aSelected, aHighlighted);
}
myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
sendOperation(anOperation);
}
}
aDisplayer->StopSelection(theFeatures, isStop, false);
+
+ XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+ aViewer->enableSelection(!isStop);
+
aDisplayer->UpdateViewer();
}
}
void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations)
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
{
setFeature(theFeature);
- myFeatures = thePresentations;
+
+ if (!theHighlighted.empty()) {
+ // if there is highlighted object, we check whether it is in the list of selected objects
+ // in that case this object is a handle of the moved lines. If there no such object in the selection,
+ // the hightlighted object should moved and the selection is skipped. The skipped selection will be
+ // deselected in the viewer by blockSelection signal in the startOperation method.
+ bool isSelected = false;
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
+ for (; anIt != aLast && !isSelected; anIt++) {
+ isSelected = (*anIt).feature() == feature();
+ }
+ if (!isSelected)
+ myFeatures = theHighlighted;
+ else
+ myFeatures = theSelected;
+ }
+ else
+ myFeatures = theSelected;
}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
return mySketch;
}
-void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
{
- if (!(theEvent->buttons() & Qt::LeftButton))
- return;
- gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
- myCurPoint.setPoint(aPoint);
+ if (myFeatures.size() == 1)
+ {
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ if (!theHighlighted.empty())
+ aFeature = theHighlighted.front().feature();
+
+ if (aFeature && aFeature == feature()) { // continue the feature edit
+ blockSelection(true);
+ }
+ else {
+ commit();
+ emit featureConstructed(feature(), FM_Deactivation);
+ if (aFeature) {
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ }
+ }
+ }
}
void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
}
void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
if (myFeatures.size() == 1) {
- if (theSelected.empty())
- return;
-
- boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
- commit();
- emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ blockSelection(false);
}
else {
commit();
{
// do nothing in order to do not create a new feature
emit multiSelectionEnabled(false);
- emit setSelection(std::list<XGUI_ViewerPrs>());
- emit stopSelection(myFeatures, true);
+
+ blockSelection(true);
+
myCurPoint.clear();
}
void PartSet_OperationEditLine::stopOperation()
{
emit multiSelectionEnabled(true);
- bool isSelectFeatures = myFeatures.size() > 1;
- emit stopSelection(myFeatures, false);
- if (isSelectFeatures)
- emit setSelection(myFeatures);
+
+ blockSelection(false, myFeatures.size() > 1);
myFeatures.clear();
}
+void PartSet_OperationEditLine::blockSelection(bool isBlocked, const bool isRestoreSelection)
+{
+ if (isBlocked) {
+ emit setSelection(std::list<XGUI_ViewerPrs>());
+ emit stopSelection(myFeatures, true);
+ }
+ else {
+ emit stopSelection(myFeatures, false);
+ if (isRestoreSelection)
+ emit setSelection(myFeatures);
+ }
+}
+
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
{
// do nothing in order to do not create a new feature
/// Initializes some fields accorging to the feature
/// \param theFeature the feature
- /// \param thePresentations the list of additional presentations
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Returns the operation sketch feature
/// \returns the sketch instance
virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
/// Processes the mouse pressed in the point
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
- virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView);
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Gives the current mouse point in the viewer
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
protected:
/// \brief Virtual method called when operation is started
/// Virtual method called when operation started (see start() method for more description)
virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
protected:
+ /// Emits a signal about the selection blocking. Emits a signal to change the selection.
+ /// If the block is true, the signal clear selection, otherwise if restore selection flag allows,
+ /// the internal operation features are to be selected
+ /// \param isBlocked the state whether the operation is blocked or unblocked
+ /// \param isRestoreSelection the state whether the selected objects should be reselected
+ void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+
/// \brief Save the point to the line.
/// \param theFeature the source feature
/// \param theDeltaX the delta for X coordinate is moved
}
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
{
- myFeatures = theSelected;
-}
-
-void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
-{
- if (theSelected.empty())
- return;
-
if (!myIsEditMode) {
- XGUI_ViewerPrs aPrs = theSelected.front();
+ XGUI_ViewerPrs aPrs = theHighlighted.front();
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
setSketchPlane(aShape);
}
}
else {
- if (theSelected.size() == 1) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+ if (theHighlighted.size() == 1) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = theHighlighted.front().feature();
if (aFeature)
emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
}
+ else
+ myFeatures = theHighlighted;
}
- myFeatures.clear();
}
void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
/// Processes the mouse pressed in the point
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
- /// Processes the mouse release in the point
- /// \param thePoint a point clicked in the viewer
- /// \param theEvent the mouse event
- /// \param theSelected the list of selected presentations
- virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
{
}
void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
{
}
void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
/// Initializes some fields accorging to the feature
- /// \param theFeature the feature
- /// \param thePresentations the list of additional presentations
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations) {}
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted) {}
/// Returns the operation sketch feature
/// \returns the sketch instance
virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
/// Processes the mouse pressed in the point
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Processes the mouse release in the point
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Processes the mouse move in the point
- /// \param thePoint a 3D point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
/// Processes the key pressed in the view
}
void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& /*thePresentations*/)
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
if (!theFeature || theFeature->getKind() != "SketchLine")
return;
}
void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
- const std::list<XGUI_ViewerPrs>& theSelected)
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
double aX, anY;
emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
}
break;
+ case Qt::Key_Escape: {
+ if (myPointSelectionMode == SM_DonePoint)
+ {
+ commit();
+ emit featureConstructed(feature(), FM_Deactivation);
+ }
+ else
+ abort();
+ }
default:
- PartSet_OperationSketchBase::keyReleased(theKey);
break;
}
}
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
/// Initializes some fields accorging to the feature
- /// \param theFeature the feature
- /// \param thePresentations the list of additional presentations
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Returns the operation sketch feature
/// \returns the sketch instance
virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
/// Gives the current selected objects to be processed by the operation
- /// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
/// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
- const std::list<XGUI_ViewerPrs>& theSelected);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
#include <ModelAPI_Data.h>
#include <AIS_InteractiveContext.hxx>
+#include <AIS_LocalContext.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
}*/
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs()
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetSelected()
{
std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
std::list<XGUI_ViewerPrs> aPresentations;
Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
TopoDS_Shape aShape = aContext->SelectedShape();
- boost::shared_ptr<ModelAPI_Feature> aFeature;
- FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
- aFLast = myFeature2AISObjectMap.end();
- for (; aFIt != aFLast && !aFeature; aFIt++) {
- Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
- if (anAIS != anIO)
- continue;
- aFeature = (*aFIt).first;
- }
+ boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
+ if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
+ continue;
+ aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ aPrsFeatures.insert(aFeature);
+ }
+ return aPresentations;
+}
+
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetHighlighted()
+{
+ std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
+ std::list<XGUI_ViewerPrs> aPresentations;
+
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
+ Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
+ TopoDS_Shape aShape = aContext->DetectedShape();
+
+ boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
boost::shared_ptr<ModelAPI_Feature> aFeature;
Handle(AIS_Shape) anAIS;
- aContext->ClearSelected();
+ // we need to unhighligth objects manually in the current local context
+ // in couple with the selection clear (TODO)
+ Handle(AIS_LocalContext) aLocalContext = aContext->LocalContext();
+ if (!aLocalContext.IsNull())
+ aLocalContext->UnhilightLastDetected(myWorkshop->viewer()->activeView());
+ aContext->ClearSelected(false);
for (; anIt != aLast; anIt++) {
aFeature = (*anIt).feature();
continue;
aContext->AddOrRemoveSelected(anAIS, false);
}
+
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
}
void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
{
- closeAllContexts(true);
+ CloseAllContexts(true);
+}
+
+boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO)
+{
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
+ aFLast = myFeature2AISObjectMap.end();
+ for (; aFIt != aFLast && !aFeature; aFIt++) {
+ Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
+ if (anAIS != theIO)
+ continue;
+ aFeature = (*aFIt).first;
+ }
+ return aFeature;
}
-void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
+void XGUI_Displayer::CloseAllContexts(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
if (!ic.IsNull()) {
//void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
// const bool isUpdateViewer = true);
- /// Returns a list of viewer presentations
+ /// Returns a list of viewer selected presentations
/// \return list of presentations
- std::list<XGUI_ViewerPrs> GetViewerPrs();
+ std::list<XGUI_ViewerPrs> GetSelected();
+
+ /// Returns a list of viewer highlited presentations
+ /// \return list of presentations
+ std::list<XGUI_ViewerPrs> GetHighlighted();
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
void UpdateViewer();
protected:
+ /// Searches the feature by interactive object
+ /// \param theIO an interactive object
+ /// \return feature the feature or NULL if it not visualized
+ boost::shared_ptr<ModelAPI_Feature> GetFeature(Handle(AIS_InteractiveObject) theIO);
/// Deactivate local selection
/// \param isUpdateViewer the state wether the viewer should be updated immediatelly
- void closeAllContexts(const bool isUpdateViewer);
+ void CloseAllContexts(const bool isUpdateViewer);
/// Returns currently installed AIS_InteractiveContext
Handle(AIS_InteractiveContext) AISContext() const;
*/
void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
{
+ myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
if (!mySelectionEnabled) return;
- myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
if ( !aView3d.IsNull() ) {
myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);