Edit for multi selection.
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- XGUI_SelectionMgr* aSelector = myWorkshop->selector();
- std::list<XGUI_ViewerPrs> aPresentations;
- if (aSelector) {
- NCollection_List<TopoDS_Shape> aList;
- aSelector->selectedShapes(aList);
- aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
- }
+ std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
}
}
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- XGUI_SelectionMgr* aSelector = myWorkshop->selector();
- std::list<XGUI_ViewerPrs> aPresentations;
- if (aSelector) {
- NCollection_List<TopoDS_Shape> aList;
- aSelector->selectedShapes(aList);
- aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
- }
+ std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
}
}
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp)
{
- aPreviewOp->init(theFeature);
+ std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
+ aPreviewOp->init(theFeature, aPresentations);
}
myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
sendOperation(anOperation);
aViewer->enableMultiselection(theEnabled);
}
-void PartSet_Module::onSelectionEnabled(bool theEnabled)
-{
- XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
- aViewer->enableSelection(theEnabled);
-}
-
void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
int theMode)
{
this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
this, SLOT(onMultiSelectionEnabled(bool)));
- connect(aPreviewOp, SIGNAL(selectionEnabled(bool)),
- this, SLOT(onSelectionEnabled(bool)));
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
/// \param theEnabled the enabled state
void onMultiSelectionEnabled(bool theEnabled);
- /// SLOT, to switch on/off the selection in the viewer
- /// \param theEnabled the enabled state
- void onSelectionEnabled(bool theEnabled);
-
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
/// \param theMode the mode appeared on the feature
return aModes;
}
-void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<XGUI_ViewerPrs>& thePresentations)
{
setFeature(theFeature);
+ myFeatures = thePresentations;
}
void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
if (!(theEvent->buttons() & Qt::LeftButton))
return;
+
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
if (myCurPoint.myIsInitialized) {
moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START);
moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END);
- /*std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
for (; anIt != aLast; anIt++) {
boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
- if (!aFeature)
+ if (!aFeature || aFeature == feature())
continue;
moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START);
moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END);
- }*/
+ }
}
myCurPoint.setPoint(aPoint);
}
void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
const std::list<XGUI_ViewerPrs>& theSelected)
{
- boost::shared_ptr<ModelAPI_Feature> aFeature;
- if (!theSelected.empty())
- aFeature = theSelected.front().feature();
-
- if (aFeature == feature())
- return;
+ std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
+ if (myFeatures.size() == 1) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ if (!theSelected.empty())
+ aFeature = theSelected.front().feature();
+
+ if (aFeature == feature())
+ return;
- commit();
- if (aFeature)
- emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ commit();
+ if (aFeature)
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ }
+ else {
+ commit();
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).feature();
+ if (aFeature)
+ emit featureConstructed(aFeature, FM_Deactivation);
+ }
+ }
}
void PartSet_OperationEditLine::startOperation()
{
// do nothing in order to do not create a new feature
- emit selectionEnabled(false);
+ emit multiSelectionEnabled(false);
myCurPoint.clear();
}
void PartSet_OperationEditLine::stopOperation()
{
- emit selectionEnabled(true);
+ emit multiSelectionEnabled(true);
+ myFeatures.clear();
}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
/// Initializes some fields accorging to the feature
/// \param theFeature the feature
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ /// \param thePresentations the list of additional presentations
+ virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<XGUI_ViewerPrs>& thePresentations);
/// Processes the mouse pressed in the point
/// \param thePoint a point clicked in the viewer
private:
boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
+ std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
Point myCurPoint; ///< the current 3D point clicked or moved
gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
};
myIsEditMode = true;
}
}
+ else {
+ if (theSelected.size() == 1) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+ if (aFeature)
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ }
+ }
}
void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView,
if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty())
return;
- boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
- theView, feature(), theSelected);
- if (aFeature)
- emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ if (theSelected.size() != 1) {
+ boost::shared_ptr<ModelAPI_Feature> aFeature = PartSet_Tools::NearestFeature(theEvent->pos(),
+ theView, feature(), theSelected);
+ if (aFeature)
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+ }
}
std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
/// Initializes some fields accorging to the feature
/// \param theFeature the feature
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature) {}
+ /// \param thePresentations the list of additional presentations
+ virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<XGUI_ViewerPrs>& thePresentations) {}
/// Processes the mouse pressed in the point
/// \param thePoint a point clicked in the viewer
/// \param theEnabled the boolean state
void multiSelectionEnabled(bool theEnabled);
- /// signal to enable/disable usual selection in the viewer
- /// \param theEnabled the boolean state
- void selectionEnabled(bool theEnabled);
-
protected:
/// Creates an operation new feature
/// In addition to the default realization it appends the created line feature to
return aModes;
}
-void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<XGUI_ViewerPrs>& /*thePresentations*/)
{
if (!theFeature)
return;
/// Initializes some fields accorging to the feature
/// \param theFeature the feature
- virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ /// \param thePresentations the list of additional presentations
+ virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<XGUI_ViewerPrs>& thePresentations);
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
#include "XGUI_Viewer.h"
#include "XGUI_Workshop.h"
#include "XGUI_ViewerProxy.h"
+#include "XGUI_Tools.h"
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
#include <AIS_Shape.hxx>
+#include <set>
+
XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
{
myWorkshop = theWorkshop;
{
}
-void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
+/*void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
const TopoDS_Shape& theShape, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
aContext->Display(anAIS, Standard_False);
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
-}
+}*/
-boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape)
-{
- 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;
- Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
- if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
- aFeature = (*aFIt).first;
- }
- }
- return aFeature;
-}
-
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs
- (const NCollection_List<TopoDS_Shape>& theShapes)
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs()
{
+ std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
std::list<XGUI_ViewerPrs> aPresentations;
- if (theShapes.IsEmpty())
- return aPresentations;
- NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes);
- for (; anIt.More(); anIt.Next()) {
- const TopoDS_Shape& aShape = anIt.Value();
- if (aShape.IsNull())
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+ 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;
+ }
+ if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
- boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(aShape);
aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ aPrsFeatures.insert(aFeature);
}
return aPresentations;
if (IsVisible(theFeature)) {
anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
if (!anAIS.IsNull()) {
+ // if the AIS object is displayed in the opened local context in some mode, additional
+ // AIS sub objects are created there. They should be rebuild for correct selecting.
+ // It is possible to correct it by closing local context before the shape set and opening
+ // after. Another workaround to thrown down the selection and reselecting the AIS.
+ // If there was a problem here, try the first solution with close/open local context.
anAIS->Set(theShape);
anAIS->Redisplay();
+ if (aContext->IsSelected(anAIS)) {
+ aContext->AddOrRemoveSelected(anAIS, false);
+ aContext->AddOrRemoveSelected(anAIS, false);
+ //aContext->SetSelected(anAIS, false);
+ }
}
}
else {
/// \param theFeature a feature instance
/// \param theShape a shape
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
- const bool isUpdateViewer = true);
+ //void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+ // const bool isUpdateViewer = true);
- /// Returns the feature, that was displayed with this shape
- /// \param theShape a shape
- boost::shared_ptr<ModelAPI_Feature> GetFeature(const TopoDS_Shape& theShape);
-
/// Returns a list of viewer presentations
- /// \param theShapes list of shapes to find corresponded features
/// \return list of presentations
- std::list<XGUI_ViewerPrs> GetViewerPrs(const NCollection_List<TopoDS_Shape>& theShapes);
+ std::list<XGUI_ViewerPrs> GetViewerPrs();
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
#include "XGUI_Tools.h"
+#include <TopoDS_Shape.hxx>
+#include <ModelAPI_Feature.h>
+
#include <QDir>
+#include <iostream>
+#include <sstream>
+
//******************************************************************
QString dir(const QString& path, bool isAbs)
{
{
return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1));
}
+
+//******************************************************************
+std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ std::ostringstream aStream;
+ if (theFeature)
+ aStream << theFeature.get();
+ return QString(aStream.str().c_str()).toStdString();
+}
+
#include <QString>
#include <QRect>
+#include <boost/shared_ptr.hpp>
+
+class TopoDS_Shape;
+class ModelAPI_Feature;
/*!
\brief Return directory part of the file path.
*/
QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2);
+/*!
+ Returns the string presentation of the given feature
+ \param theFeature a feature
+*/
+std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
#endif