return myDescription;
}
-bool ModuleBase_IOperation::isGranted() const
+bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
{
return false;
}
/// must be always can start above any launched one. Default impl returns FALSE,
/// so it is being checked for IsValid, but some operations may overload IsGranted()
/// In this case they will always start, no matter what operation is running.
- virtual bool isGranted() const;
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
signals:
void started(); /// the operation is started
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
- aType == EVENT_FEATURE_CREATED)
- myModule->visualizePreview(aFeature, true);
+ aType == EVENT_FEATURE_CREATED) {
+ myModule->visualizePreview(aFeature, true, false);
+ if (aType == EVENT_FEATURE_CREATED)
+ myModule->activateFeature(aFeature, true);
+ myModule->workshop()->displayer()->UpdateViewer();
+ }
}
if (aType == EVENT_FEATURE_DELETED)
{
aViewer->enableMultiselection(theEnabled);
}
+void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ if (!isStop) {
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ for (; anIt != aLast; anIt++) {
+ activateFeature((*anIt).feature(), false);
+ }
+ }
+ aDisplayer->StopSelection(theFeatures, isStop, false);
+ aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures)
+{
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->SetSelected(theFeatures, false);
+ aDisplayer->UpdateViewer();
+}
+
void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort;
- visualizePreview(theFeature, isDisplay);
+ visualizePreview(theFeature, isDisplay, false);
+
+ if (theMode == PartSet_OperationSketchBase::FM_Activation ||
+ theMode == PartSet_OperationSketchBase::FM_Deactivation)
+ activateFeature(theFeature, true);
}
ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
else if(theCmdId == PartSet_OperationSketchLine::Type() ||
theCmdId == PartSet_OperationEditLine::Type()) {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
- boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
- if (aCurOperation)
- aSketchFeature = aCurOperation->feature();
+ boost::shared_ptr<ModelAPI_Feature> aSketch;
+ PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+ if (aPrevOp)
+ aSketch = aPrevOp->sketch();
if (theCmdId == PartSet_OperationSketchLine::Type())
- anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature);
+ anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
else
- anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature);
+ anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
}
else {
anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
this, SLOT(onMultiSelectionEnabled(bool)));
+ connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
+ this, SLOT(onMultiSelectionEnabled(bool)));
+ connect(aPreviewOp, SIGNAL(stopSelection(const std::list<XGUI_ViewerPrs>&, const bool)),
+ this, SLOT(onStopSelection(const std::list<XGUI_ViewerPrs>&, const bool)));
+ connect(aPreviewOp, SIGNAL(setSelection(const std::list<XGUI_ViewerPrs>&)),
+ this, SLOT(onSetSelection(const std::list<XGUI_ViewerPrs>&)));
+
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
Events_Loop::loop()->send(aMessage);
}
-void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+ const bool isUpdateViewer)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
if (!anOperation)
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
- aDisplayer->RedisplayInLocalContext(theFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
- aPreviewOp->getSelectionModes(theFeature));
+ aDisplayer->Redisplay(theFeature,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
}
- else {
- //aDisplayer->CloseLocalContexts(false);
- aDisplayer->Erase(anOperation->feature());
+ else
+ aDisplayer->Erase(anOperation->feature(), false);
+
+ if (isUpdateViewer)
+ aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const bool isUpdateViewer)
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+ isUpdateViewer);
}
}
for (; anIt != aLast; anIt++) {
boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
- aDisplayer->RedisplayInLocalContext(aFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
- aModes, false);
+ aDisplayer->Redisplay(aFeature,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+ aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
}
aDisplayer->UpdateViewer();
}
class QKeyEvent;
class PartSet_Listener;
class ModelAPI_Feature;
+class XGUI_ViewerPrs;
class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
{
virtual void launchOperation(const QString& theCmdId);
/// Displays or erase the current operation preview, if it has it.
- /// \param theF
+ /// \param theFeature the feature instance to be displayed
/// \param isDisplay the state whether the presentation should be displayed or erased
- void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay);
+ /// \param isUpdateViewer the flag whether the viewer should be updated
+ void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+ const bool isUpdateViewer = true);
+
+ /// Activates the feature in the displayer
+ /// \param theFeature the feature instance to be displayed
+ /// \param isUpdateViewer the flag whether the viewer should be updated
+ void activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const bool isUpdateViewer);
/// Updates current operation preview, if it has it.
/// \param theCmdId the operation name
/// \param theEnabled the enabled state
void onMultiSelectionEnabled(bool theEnabled);
+ /// SLOT, to stop or start selection mode for the features
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ void onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop);
+
+ /// SLOT, to set selection
+ /// \param theFeatures a list of features to be selected
+ void onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
+
/// 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
#include <PartSet_OperationEditLine.h>
#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+
+#include <ModuleBase_OperationDescription.h>
#include <XGUI_ViewerPrs.h>
{
}
-bool PartSet_OperationEditLine::isGranted() const
+bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const
{
- return true;
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
}
std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
- std::list<int> aModes;
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- return aModes;
+ return PartSet_OperationSketchBase::getSelectionModes(theFeature);
}
void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
myFeatures = thePresentations;
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
+{
+ return mySketch;
+}
+
void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
if (!(theEvent->buttons() & Qt::LeftButton))
if (myCurPoint.myIsInitialized) {
double aCurX, aCurY;
- PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
+ PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
double aX, anY;
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
{
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())
+ if (theSelected.empty())
return;
-
- commit();
- if (aFeature)
- emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+
+ boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+ commit();
+ emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
}
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);
myCurPoint.clear();
}
void PartSet_OperationEditLine::stopOperation()
{
emit multiSelectionEnabled(true);
+ bool isSelectFeatures = myFeatures.size() > 1;
+ emit stopSelection(myFeatures, false);
+ if (isSelectFeatures)
+ emit setSelection(myFeatures);
+
myFeatures.clear();
}
/// Destructor
virtual ~PartSet_OperationEditLine();
- /// Returns that this operator can be started above already running one.
- /// The runned operation should be the sketch feature modified operation
- virtual bool isGranted() const;
+ /// Returns that this operator can be started above already running one.
+ /// The runned operation should be the sketch feature modified operation
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations);
+ /// 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
std::list<int> aModes;
if (!myIsEditMode)
aModes.push_back(TopAbs_FACE);
- else {
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- }
+ else
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
return aModes;
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+{
+ return feature();
+}
+
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
const std::list<XGUI_ViewerPrs>& theSelected)
{
/// \return the selection mode
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
+ /// 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
#include <PartSet_OperationSketchBase.h>
#include <SketchPlugin_Feature.h>
-#include <Model_Object.h>
+#include <ModelAPI_Object.h>
#include <V3d_View.hxx>
boost::shared_ptr<SketchPlugin_Feature> aFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
if (!aFeature) { // if it is reference to a object feature
- boost::shared_ptr<Model_Object> anObj =
- boost::dynamic_pointer_cast<Model_Object>(theFeature);
+ boost::shared_ptr<ModelAPI_Object> anObj =
+ boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
if (anObj)
aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
}
return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
}
+std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+ std::list<int> aModes;
+ aModes.push_back(TopAbs_VERTEX);
+ aModes.push_back(TopAbs_EDGE);
+ return aModes;
+}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
{
boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature();
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations) {}
+ /// 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 theEnabled the boolean state
void multiSelectionEnabled(bool theEnabled);
+ /// signal to enable/disable selection in the viewer
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool theToStop);
+ /// signal to set selection in the viewer
+ /// \param theFeatures a list of features to be disabled
+ void setSelection(const std::list<XGUI_ViewerPrs>& theFeatures);
+
/// signal to enable/disable usual selection in the viewer
/// \param theEnabled the boolean state
void selectionEnabled(bool theEnabled);
#include <PartSet_OperationSketchLine.h>
#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <GeomDataAPI_Point2D.h>
+
+#include <ModuleBase_OperationDescription.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
{
}
-bool PartSet_OperationSketchLine::isGranted() const
+bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
{
- return true;
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
}
std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
std::list<int> aModes;
if (theFeature != feature())
- {
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- }
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
return aModes;
}
myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
+{
+ return mySketch;
+}
+
void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
const std::list<XGUI_ViewerPrs>& theSelected)
{
bool isFoundPoint = false;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
if (theSelected.empty()) {
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
isFoundPoint = true;
}
else {
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
if (!aVertex.IsNull()) {
aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
isFoundPoint = true;
setConstraints(aX, anY);
double Y0, Y1, Y2, Y3;
getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
switch (myPointSelectionMode) {
case SM_FirstPoint:
switch (myPointSelectionMode)
{
case SM_FirstPoint: {
- setLinePoint(aX, anY, LINE_ATTR_START);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_START);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_END);
myPointSelectionMode = SM_SecondPoint;
}
break;
case SM_SecondPoint: {
- setLinePoint(aX, anY, LINE_ATTR_END);
+ setLinePoint(feature(), aX, anY, LINE_ATTR_END);
commit();
emit featureConstructed(feature(), FM_Deactivation);
emit launchOperation(PartSet_OperationSketchLine::Type(), feature());
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
{
boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
- if (mySketch) {
+ if (sketch()) {
boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
aFeature->addSub(aNewFeature);
}
if (myInitPoint) {
+ setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START);
+ setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END);
+
boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(LINE_ATTR_START));
- aPoint->setValue(myInitPoint->x(), myInitPoint->y());
-
createConstraint(myInitPoint, aPoint);
}
boost::shared_ptr<ModelAPI_Document> aDoc = document();
boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
- if (mySketch) {
+ if (sketch()) {
boost::shared_ptr<SketchPlugin_Feature> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
aSketch->addSub(aFeature);
}
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(aPointArg));
- aData = mySketch->data();
+ aData = sketch()->data();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
return aPoint2D;
}
-void PartSet_OperationSketchLine::setLinePoint(double theX, double theY,
+void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ double theX, double theY,
const std::string& theAttribute)
{
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!theFeature)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
aPoint->setValue(theX, theY);
const std::string& theAttribute)
{
double aX, anY;
- PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY);
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
/// Returns that this operator can be started above already running one.
/// The runned operation should be the sketch feature modified operation
- virtual bool isGranted() const;
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations);
+ /// 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
double theX, double theY);
/// \brief Save the point to the line.
+ /// \param theFeature the line feature
/// \param theX the horizontal coordinate
/// \param theY the vertical coordinate
/// \param theAttribute the start or end attribute of the line
- void setLinePoint(double theX, double theY, const std::string& theAttribute);
+ void setLinePoint(boost::shared_ptr<ModelAPI_Feature>, double theX, double theY,
+ const std::string& theAttribute);
/// \brief Save the point to the line.
/// \param thePoint the 3D point in the viewer
/// \param theAttribute the start or end attribute of the line
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
#include <ModelAPI_AttributeRefList.h>
SketchPlugin_Feature::SketchPlugin_Feature()
mySketch = 0;
}
-void SketchPlugin_Feature::setData(boost::shared_ptr<ModelAPI_Data> theData)
-{
- ModelAPI_Feature::setData(theData);
-
- // find sketch that references to this feature
- int aSketches = document()->size("Construction");
- for(int a = 0; a < aSketches && !mySketch; a++) {
- boost::shared_ptr<SketchPlugin_Sketch> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a));
- if (aSketch) {
- std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
- aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
- std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
- for(; aSub != aList.end(); aSub++) {
- if ((*aSub)->data()->isEqual(theData)) {
- mySketch = aSketch.get();
- break;
- }
- }
- }
- }
-}
-
void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
{
myPreview = theShape;
{
return myPreview;
}
+
+SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
+{
+ if (!mySketch) {
+ // find sketch that references to this feature
+ int aSketches = document()->size("Construction");
+ for(int a = 0; a < aSketches && !mySketch; a++) {
+ boost::shared_ptr<ModelAPI_Object> anObj =
+ boost::dynamic_pointer_cast<ModelAPI_Object>(document()->feature("Construction", a));
+ if (anObj) {
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj->featureRef());
+ if (aSketch) {
+ std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
+ aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+ std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+ for(; aSub != aList.end(); aSub++) {
+ if ((*aSub)->data()->isEqual(data())) {
+ mySketch = aSketch.get();
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ return mySketch;
+}
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
/// Returns the sketch of this feature
- SketchPlugin_Sketch* sketch() {return mySketch;}
+ SketchPlugin_Sketch* sketch();
/// initializes mySketch
SketchPlugin_Feature();
- /// Sets the data manager of an object and here initializes mySketch field
- SKETCHPLUGIN_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData);
friend class SketchPlugin_Sketch;
aContext->UpdateCurrentViewer();
}
-void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape,
- const std::list<int>& theModes, const bool isUpdateViewer)
+void XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
if (!aContext->HasOpenedContext()) {
aContext->ClearCurrents(false);
- aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
- true/*allow shape decomposition*/);
+ aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
}
// display or redisplay presentation
Handle(AIS_Shape) anAIS;
// If there was a problem here, try the first solution with close/open local context.
anAIS->Set(theShape);
anAIS->Redisplay();
- if (aContext->IsSelected(anAIS)) {
+
+ /*if (aContext->IsSelected(anAIS)) {
aContext->AddOrRemoveSelected(anAIS, false);
aContext->AddOrRemoveSelected(anAIS, false);
//aContext->SetSelected(anAIS, false);
- }
+ }*/
}
}
else {
myFeature2AISObjectMap[theFeature] = anAIS;
aContext->Display(anAIS, false);
}
+}
+
+void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<int>& theModes, const bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ // Open local context if there is no one
+ if (!aContext->HasOpenedContext()) {
+ aContext->ClearCurrents(false);
+ aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+ }
+ // display or redisplay presentation
+ Handle(AIS_Shape) anAIS;
+ if (IsVisible(theFeature))
+ anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
+
// Activate selection of objects from prs
if (!anAIS.IsNull()) {
- aContext->Load(anAIS, -1, true/*allow decomposition*/);
+ aContext->Load(anAIS, -1, true/*allow decomposition*/);
+ aContext->Deactivate(anAIS);
+
std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
for (; anIt != aLast; anIt++)
{
aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
+ }
+ }
+
+ if (isUpdateViewer)
+ aContext->UpdateCurrentViewer();
+}
+
+void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+ const bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+
+ Handle(AIS_Shape) anAIS;
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ for (; anIt != aLast; anIt++) {
+ aFeature = (*anIt).feature();
+ if (IsVisible(aFeature))
+ anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
+ if (anAIS.IsNull())
+ continue;
+
+ if (isStop) {
+ QColor aColor(Qt::white);
+ anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+ anAIS->Redisplay();
+ }
+ else {
+ QColor aColor(Qt::red);
+ anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+ anAIS->Redisplay();
}
}
+ if (isUpdateViewer)
+ aContext->UpdateCurrentViewer();
+}
+
+void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ Handle(AIS_Shape) anAIS;
+ aContext->ClearSelected();
+
+ for (; anIt != aLast; anIt++) {
+ aFeature = (*anIt).feature();
+ if (IsVisible(aFeature))
+ anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
+ if (anAIS.IsNull())
+ continue;
+ aContext->AddOrRemoveSelected(anAIS, false);
+ }
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
}
for (; aFIt != aFLast; aFIt++)
{
boost::shared_ptr<ModelAPI_Feature> aFeature = (*aFIt).first;
- if (!aFeature || !aFeature->data()->isValid()) {
+ if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
if (!anAIS.IsNull()) {
aContext->Erase(anAIS, false);
/// \param theShape a shape
/// \param theMode a local selection mode
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape,
- const std::list<int>& theMode, const bool isUpdateViewer = true);
+ void Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+
+ /// Display the shape and activate selection of sub-shapes
+ /// \param theFeature a feature instance
+ /// \param theShape a shape
+ /// \param theMode a list of local selection modes
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ void ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<int>& theModes, const bool isUpdateViewer = true);
+
+ /// Stop the current selection and color the given features to the selection color
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ void StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
+ const bool isUpdateViewer);
+
+ /// Set the features are selected
+ /// \param theFeatures a list of features to be selected
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ void SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
/// Erase the feature and a shape.
/// \param theFeature a feature instance
FeatureToAISMap myFeature2AISObjectMap;
};
+
#endif
{
bool aCanStart = true;
ModuleBase_Operation* aCurrentOp = currentOperation();
- if (aCurrentOp && !theOperation->isGranted())
+ if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
{
if (canStopOperation()) {
aCurrentOp->abort();
{
std::ostringstream aStream;
if (theFeature)
- aStream << theFeature.get();
+ aStream << theFeature.get() << " " << theFeature->getKind();
return QString(aStream.str().c_str()).toStdString();
}