PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
QObject* theParent)
-: PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
+: PartSet_OperationSketchBase(theId, theParent)
{
}
std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
std::list<int> aModes;
- if (!myIsEditMode)
+ if (!hasSketchPlane())
aModes.push_back(TopAbs_FACE);
else
aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
const std::list<XGUI_ViewerPrs>& /*theSelected*/,
const std::list<XGUI_ViewerPrs>& theHighlighted)
{
- if (!myIsEditMode) {
+ if (!hasSketchPlane()) {
XGUI_ViewerPrs aPrs = theHighlighted.front();
const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull()) {
+ if (!aShape.IsNull())
setSketchPlane(aShape);
- myIsEditMode = true;
- }
}
else {
if (theHighlighted.size() == 1) {
void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
- if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
+ if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
return;
if (myFeatures.size() != 1) {
emit closeLocalContext();
}
+bool PartSet_OperationSketch::isNestedOperationsEnabled() const
+{
+ return hasSketchPlane();
+}
+
+bool PartSet_OperationSketch::hasSketchPlane() const
+{
+ bool aHasPlane = false;
+
+ if (feature()) {
+ // set plane parameters to feature
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+ // temporary solution for main planes only
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ double aX = aNormal->x(), anY = aNormal->y(), aZ = aNormal->z();
+
+ aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+ }
+ return aHasPlane;
+}
+
void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
{
if (theShape.IsNull())
aPlane->coefficients(anA, aB, aC, aD);
boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
- /*
- aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
- aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
- aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
- aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
- */
// temporary solution for main planes only
boost::shared_ptr<GeomDataAPI_Point> anOrigin =
boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
/// Emits a signal to hide the preview of the operation
virtual void stopOperation();
+ /// Returns whether the nested operations are enabled.
+ /// The state can depend on the operation current state.
+ /// It returns true after the sketch plane is choosen.
+ /// \return enabled state
+ virtual bool isNestedOperationsEnabled() const;
+
signals:
/// signal about the sketch plane is selected
/// \param theX the value in the X direction of the plane
void planeSelected(double theX, double theY, double theZ);
protected:
+ /// Returns whether the sketch plane is set
+ /// \return the boolean value whether the sketch is set
+ bool hasSketchPlane() const;
+
/// Set the plane to the current sketch
/// \param theShape the shape
void setSketchPlane(const TopoDS_Shape& theShape);
private:
- bool myIsEditMode; /// the edit mode of this operation
std::list<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
};