diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index 662f0d87290c..ecdefd60d6c5 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -53,6 +53,7 @@ using namespace Part; const int Part2DObject::H_Axis = -1; const int Part2DObject::V_Axis = -2; +const int Part2DObject::N_Axis = -3; PROPERTY_SOURCE(Part::Part2DObject, Part::Feature) @@ -215,6 +216,9 @@ Base::Axis Part2DObject::getAxis(int axId) const else if (axId == V_Axis) { return Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,1,0)); } + else if (axId == N_Axis) { + return Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,0,1)); + } return Base::Axis(); } diff --git a/src/Mod/Part/App/Part2DObject.h b/src/Mod/Part/App/Part2DObject.h index 1adf5c14d610..bb4e879d7068 100644 --- a/src/Mod/Part/App/Part2DObject.h +++ b/src/Mod/Part/App/Part2DObject.h @@ -92,6 +92,7 @@ class PartExport Part2DObject : public Part::Feature static const int H_Axis; static const int V_Axis; + static const int N_Axis; /** @name methods overide Feature */ //@{ diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 766a5a0177e5..09f98141b8dc 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -34,8 +34,9 @@ #include "FeatureLinearPattern.h" -#include #include +#include +#include using namespace PartDesign; @@ -47,7 +48,6 @@ PROPERTY_SOURCE(PartDesign::LinearPattern, PartDesign::Transformed) LinearPattern::LinearPattern() { ADD_PROPERTY_TYPE(Direction,(0),"LinearPattern",(App::PropertyType)(App::Prop_None),"Direction"); - ADD_PROPERTY(StdDirection,("")); ADD_PROPERTY(Reversed,(0)); ADD_PROPERTY(Length,(100.0)); ADD_PROPERTY(Occurrences,(3)); @@ -56,7 +56,6 @@ LinearPattern::LinearPattern() short LinearPattern::mustExecute() const { if (Direction.isTouched() || - StdDirection.isTouched() || Reversed.isTouched() || Length.isTouched() || Occurrences.isTouched()) @@ -66,7 +65,6 @@ short LinearPattern::mustExecute() const const std::list LinearPattern::getTransformations(const std::vector) { - std::string stdDirection = StdDirection.getValue(); float distance = Length.getValue(); if (distance < Precision::Confusion()) throw Base::Exception("Pattern length too small"); @@ -75,37 +73,35 @@ const std::list LinearPattern::getTransformations(const std::vectorgetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + throw Base::Exception("Direction reference must be edge or face of a feature"); + std::vector subStrings = Direction.getSubValues(); + if (subStrings.empty() || subStrings[0].empty()) + throw Base::Exception("No direction reference specified"); + + gp_Dir dir; + if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { + Part::Part2DObject* refSketch = static_cast(refObject); + Base::Axis axis; + if (subStrings[0] == "H_Axis") + axis = refSketch->getAxis(Part::Part2DObject::H_Axis); + else if (subStrings[0] == "V_Axis") + axis = refSketch->getAxis(Part::Part2DObject::V_Axis); + else if (subStrings[0] == "N_Axis") + axis = refSketch->getAxis(Part::Part2DObject::N_Axis); + else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") { + int AxId = std::atoi(subStrings[0].substr(4,4000).c_str()); + if (AxId >= 0 && AxId < refSketch->getAxisCount()) + axis = refSketch->getAxis(AxId); } + axis *= refSketch->Placement.getValue(); + dir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z); } else { - App::DocumentObject* refObject = Direction.getValue(); - if (refObject == NULL) - throw Base::Exception("No direction specified"); - if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("Direction reference must be edge or face of a feature"); - std::vector subStrings = Direction.getSubValues(); - if (subStrings.empty() || subStrings[0].empty()) - throw Base::Exception("No direction reference specified"); - Part::Feature* refFeature = static_cast(refObject); Part::TopoShape refShape = refFeature->Shape.getShape(); TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str()); @@ -119,8 +115,6 @@ const std::list LinearPattern::getTransformations(const std::vector LinearPattern::getTransformations(const std::vectorgetLocation().Inverted(); - dir.Transform(invObjLoc.Transformation()); } + TopLoc_Location invObjLoc = this->getLocation().Inverted(); + dir.Transform(invObjLoc.Transformation()); - // get the support placement - // TODO: Check for NULL pointer - /*Part::Feature* supportFeature = static_cast(originals.front()); - if (supportFeature == NULL) - throw Base::Exception("Cannot work on invalid support shape"); - Base::Placement supportPlacement = supportFeature->Placement.getValue(); - dir *= supportPlacement; - gp_Vec direction(dir.getDirection().x, dir.getDirection().y, dir.getDirection().z);*/ gp_Vec direction(dir.X(), dir.Y(), dir.Z()); if (reversed) diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.h b/src/Mod/PartDesign/App/FeatureLinearPattern.h index 687744174439..1e9878478c10 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.h +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.h @@ -39,7 +39,6 @@ class PartDesignExport LinearPattern : public PartDesign::Transformed LinearPattern(); App::PropertyLinkSub Direction; - App::PropertyString StdDirection; App::PropertyBool Reversed; App::PropertyFloat Length; App::PropertyInteger Occurrences; @@ -58,8 +57,6 @@ class PartDesignExport LinearPattern : public PartDesign::Transformed * Returns a list of (Occurrences - 1) transformations since the first, untransformed instance * is not counted. Each transformation will move the shape it is applied to by the distance * (Length / (Occurrences - 1)) so that the transformations will cover the total Length. - * If StdDirection is "X", "Y" or "Z" then the transformation direction will be parallel to the - * corresponding axis * If Direction contains a feature and a face name, then the transformation direction will be * the normal of the given face, which must be planar. If it contains an edge name, then the * transformation direction will be parallel to the given edge, which must be linear diff --git a/src/Mod/PartDesign/App/FeatureMirrored.cpp b/src/Mod/PartDesign/App/FeatureMirrored.cpp index 42913f129d32..29aa2bc53095 100644 --- a/src/Mod/PartDesign/App/FeatureMirrored.cpp +++ b/src/Mod/PartDesign/App/FeatureMirrored.cpp @@ -33,6 +33,7 @@ #include "FeatureMirrored.h" #include +#include using namespace PartDesign; @@ -44,45 +45,47 @@ PROPERTY_SOURCE(PartDesign::Mirrored, PartDesign::Transformed) Mirrored::Mirrored() { ADD_PROPERTY_TYPE(MirrorPlane,(0),"Mirrored",(App::PropertyType)(App::Prop_None),"Mirror plane"); - ADD_PROPERTY(StdMirrorPlane,("")); } short Mirrored::mustExecute() const { - if (MirrorPlane.isTouched() || - StdMirrorPlane.isTouched()) + if (MirrorPlane.isTouched()) return 1; return Transformed::mustExecute(); } const std::list Mirrored::getTransformations(const std::vector) { - App::DocumentObject* ref = MirrorPlane.getValue(); + App::DocumentObject* refObject = MirrorPlane.getValue(); + if (refObject == NULL) + throw Base::Exception("No mirror plane reference specified"); + if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + throw Base::Exception("Mirror plane reference must be face of a feature"); std::vector subStrings = MirrorPlane.getSubValues(); - std::string stdPlane = StdMirrorPlane.getValue(); - - gp_Pnt p; - gp_Dir d; - if (!stdPlane.empty()) { - p = gp_Pnt(0,0,0); - if (stdPlane == "XY") { - d = gp_Dir(0,0,1); - } else if (stdPlane == "XZ") { - d = gp_Dir(0,1,0); - } else if(stdPlane == "YZ") { - d = gp_Dir(1,0,0); - } else { - throw Base::Exception("Invalid mirror plane (must be XY, XZ or YZ)"); + if (subStrings.empty() || subStrings[0].empty()) + throw Base::Exception("No mirror plane reference specified"); + + gp_Pnt axbase; + gp_Dir axdir; + if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { + Part::Part2DObject* refSketch = static_cast(refObject); + Base::Axis axis; + if (subStrings[0] == "H_Axis") + axis = refSketch->getAxis(Part::Part2DObject::V_Axis); + else if (subStrings[0] == "V_Axis") + axis = refSketch->getAxis(Part::Part2DObject::H_Axis); + else if (subStrings[0] == "") + axis = refSketch->getAxis(Part::Part2DObject::N_Axis); + else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") { + int AxId = std::atoi(subStrings[0].substr(4,4000).c_str()); + if (AxId >= 0 && AxId < refSketch->getAxisCount()) + axis = refSketch->getAxis(AxId); } + axis *= refSketch->Placement.getValue(); + axbase = gp_Pnt(axis.getBase().x, axis.getBase().y, axis.getBase().z); + axdir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z); } else { - if (ref == NULL) - throw Base::Exception("No mirror plane selected"); - if (!ref->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("Mirror plane must be face of a feature"); - Part::TopoShape baseShape = static_cast(ref)->Shape.getShape(); - - if (subStrings.empty() || subStrings[0].empty()) - throw Base::Exception("No mirror plane defined"); + Part::TopoShape baseShape = static_cast(refObject)->Shape.getShape(); // TODO: Check for multiple mirror planes? TopoDS_Face face = TopoDS::Face(baseShape.getSubShape(subStrings[0].c_str())); @@ -92,22 +95,14 @@ const std::list Mirrored::getTransformations(const std::vectorgetLocation().Inverted(); - p.Transform(invObjLoc.Transformation()); - d.Transform(invObjLoc.Transformation()); + axbase = getPointFromFace(face); + axdir = adapt.Plane().Axis().Direction(); } + TopLoc_Location invObjLoc = this->getLocation().Inverted(); + axbase.Transform(invObjLoc.Transformation()); + axdir.Transform(invObjLoc.Transformation()); - // get the support placement - // TODO: Check for NULL pointer - /*Part::Feature* supportFeature = static_cast(originals.front()); - if (supportFeature == NULL) - throw Base::Exception("Cannot work on invalid support shape"); - Base::Placement supportPlacement = supportFeature->Placement.getValue(); - ax *= supportPlacement; - gp_Ax2 mirrorAxis(gp_Pnt(ax.getBase().x, ax.getBase().y, ax.getBase().z), gp_Dir(ax.getDirection().x, ax.getDirection().y, ax.getDirection().z));*/ - gp_Ax2 mirrorAxis(p, d); + gp_Ax2 mirrorAxis(axbase, axdir); std::list transformations; gp_Trsf trans; diff --git a/src/Mod/PartDesign/App/FeatureMirrored.h b/src/Mod/PartDesign/App/FeatureMirrored.h index b89c0500c28f..02c57b50c4b6 100644 --- a/src/Mod/PartDesign/App/FeatureMirrored.h +++ b/src/Mod/PartDesign/App/FeatureMirrored.h @@ -39,7 +39,6 @@ class PartDesignExport Mirrored : public PartDesign::Transformed Mirrored(); App::PropertyLinkSub MirrorPlane; - App::PropertyString StdMirrorPlane; /** @name methods override feature */ //@{ @@ -54,7 +53,6 @@ class PartDesignExport Mirrored : public PartDesign::Transformed /** Create transformations * Returns a list containing one transformation since the first, untransformed instance * is not counted. The transformation will mirror the shape it is applied to on a plane - * If StdMirrorPlane is "XY", "YZ" or "YZ" then the mirror plane will the corresponding plane * If MirrorPlane contains a feature and an face name, then the mirror plane will be * the the given face, which must be planar */ diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index 90e6b228a92e..b4346954cf2a 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -32,9 +32,10 @@ #include "FeaturePolarPattern.h" -#include #include +#include #include +#include using namespace PartDesign; @@ -46,7 +47,6 @@ PROPERTY_SOURCE(PartDesign::PolarPattern, PartDesign::Transformed) PolarPattern::PolarPattern() { ADD_PROPERTY_TYPE(Axis,(0),"PolarPattern",(App::PropertyType)(App::Prop_None),"Direction"); - ADD_PROPERTY(StdAxis,("")); ADD_PROPERTY(Reversed,(0)); ADD_PROPERTY(Angle,(360.0)); ADD_PROPERTY(Occurrences,(3)); @@ -55,7 +55,6 @@ PolarPattern::PolarPattern() short PolarPattern::mustExecute() const { if (Axis.isTouched() || - StdAxis.isTouched() || Reversed.isTouched() || Angle.isTouched() || Occurrences.isTouched()) @@ -65,7 +64,6 @@ short PolarPattern::mustExecute() const const std::list PolarPattern::getTransformations(const std::vector) { - std::string stdAxis = StdAxis.getValue(); float angle = Angle.getValue(); if (angle < Precision::Confusion()) throw Base::Exception("Pattern angle too small"); @@ -80,32 +78,35 @@ const std::list PolarPattern::getTransformations(const std::vector(angle) / (occurrences - 1); + App::DocumentObject* refObject = Axis.getValue(); + if (refObject == NULL) + throw Base::Exception("No axis reference specified"); + if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + throw Base::Exception("Axis reference must be edge of a feature"); + std::vector subStrings = Axis.getSubValues(); + if (subStrings.empty() || subStrings[0].empty()) + throw Base::Exception("No axis reference specified"); + gp_Pnt axbase; gp_Dir axdir; - if (!stdAxis.empty()) { - axbase = gp_Pnt(0,0,0); - if (stdAxis == "X") { - axdir = gp_Dir(1,0,0); - //ax = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(1,0,0)); - } else if (stdAxis == "Y") { - axdir = gp_Dir(0,1,0); - //ax = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,1,0)); - } else if(stdAxis == "Z") { - axdir = gp_Dir(0,0,1); - //ax = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,0,1)); - } else { - throw Base::Exception("Invalid axis (must be X, Y or Z)"); + if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { + Part::Part2DObject* refSketch = static_cast(refObject); + Base::Axis axis; + if (subStrings[0] == "H_Axis") + axis = refSketch->getAxis(Part::Part2DObject::H_Axis); + else if (subStrings[0] == "V_Axis") + axis = refSketch->getAxis(Part::Part2DObject::V_Axis); + else if (subStrings[0] == "N_Axis") + axis = refSketch->getAxis(Part::Part2DObject::N_Axis); + else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") { + int AxId = std::atoi(subStrings[0].substr(4,4000).c_str()); + if (AxId >= 0 && AxId < refSketch->getAxisCount()) + axis = refSketch->getAxis(AxId); } + axis *= refSketch->Placement.getValue(); + axbase = gp_Pnt(axis.getBase().x, axis.getBase().y, axis.getBase().z); + axdir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z); } else { - App::DocumentObject* refObject = Axis.getValue(); - if (refObject == NULL) - throw Base::Exception("No axis specified"); - if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) - throw Base::Exception("Axis reference must be edge of a feature"); - std::vector subStrings = Axis.getSubValues(); - if (subStrings.empty() || subStrings[0].empty()) - throw Base::Exception("No axis reference specified"); - Part::Feature* refFeature = static_cast(refObject); Part::TopoShape refShape = refFeature->Shape.getShape(); TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str()); @@ -123,20 +124,11 @@ const std::list PolarPattern::getTransformations(const std::vectorgetLocation().Inverted(); - axbase.Transform(invObjLoc.Transformation()); - axdir.Transform(invObjLoc.Transformation()); } + TopLoc_Location invObjLoc = this->getLocation().Inverted(); + axbase.Transform(invObjLoc.Transformation()); + axdir.Transform(invObjLoc.Transformation()); - // get the support placement - // TODO: Check for NULL pointer - /*Part::Feature* supportFeature = static_cast(originals.front()); - if (supportFeature == NULL) - throw Base::Exception("Cannot work on invalid support shape"); - Base::Placement supportPlacement = supportFeature->Placement.getValue(); - ax *= supportPlacement; - gp_Ax2 axis(gp_Pnt(ax.getBase().x, ax.getBase().y, ax.getBase().z), gp_Dir(ax.getDirection().x, ax.getDirection().y, ax.getDirection().z));*/ gp_Ax2 axis(axbase, axdir); if (reversed) diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.h b/src/Mod/PartDesign/App/FeaturePolarPattern.h index 4b05494bfbb1..1916184839dd 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.h +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.h @@ -39,7 +39,6 @@ class PartDesignExport PolarPattern : public PartDesign::Transformed PolarPattern(); App::PropertyLinkSub Axis; - App::PropertyString StdAxis; App::PropertyBool Reversed; App::PropertyFloat Angle; App::PropertyInteger Occurrences; @@ -60,7 +59,6 @@ class PartDesignExport PolarPattern : public PartDesign::Transformed * (Angle / (Occurrences - 1)) so that the transformations will cover the total Angle. The only * exception is Angle = 360 degrees in which case the transformation angle will be * (Angle / Occurrences) so that the last transformed shape is not identical with the original shape - * If StdAxis is "X", "Y" or "Z" then the transformation axis will the corresponding axis * If Axis contains a feature and an edge name, then the transformation axis will be * the the given edge, which must be linear * If Reversed is true, the direction of rotation will be opposite diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 5edc850c739e..8eed4f07b0cd 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -65,7 +65,6 @@ #include #include "FeatureSketchBased.h" -#include using namespace PartDesign; diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index 8e55f17d0322..bfbe814f4d11 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -80,6 +80,15 @@ App::DocumentObject* Transformed::getSupportObject() const return NULL; } +App::DocumentObject* Transformed::getSketchObject() const +{ + std::vector originals = Originals.getValues(); + if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::SketchBased::getClassTypeId())) + return (static_cast(originals.front()))->getVerifiedSketch(); + else + return NULL; +} + short Transformed::mustExecute() const { if (Originals.isTouched()) diff --git a/src/Mod/PartDesign/App/FeatureTransformed.h b/src/Mod/PartDesign/App/FeatureTransformed.h index ab2b29f6a8af..df8174819b83 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.h +++ b/src/Mod/PartDesign/App/FeatureTransformed.h @@ -52,6 +52,9 @@ class PartDesignExport Transformed : public PartDesign::Feature /// Return first original, which serves as "Support" until Body feature becomes functional App::DocumentObject* getSupportObject() const; + /// Return the sketch of the first original + App::DocumentObject* getSketchObject() const; + /// Get the list of transformations describing the members of the pattern // Note: Only the Scaled feature requires the originals virtual const std::list getTransformations(const std::vector originals) { diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 4bb0b006a958..99d7cf1fe2e3 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -895,7 +895,10 @@ void CmdPartDesignMirrored::activated(int iMsg) // Exception (Thu Sep 6 11:52:01 2012): 'App.Document' object has no attribute 'Mirrored' updateActive(); // Helps to ensure that the object already exists when the next command comes up doCommand(Doc,str.str().c_str()); - doCommand(Doc,"App.activeDocument().%s.StdMirrorPlane = \"XY\"", FeatName.c_str()); + Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(); + if (sketch) + doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", + FeatName.c_str(), sketch->getNameInDocument()); for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); @@ -967,7 +970,10 @@ void CmdPartDesignLinearPattern::activated(int iMsg) doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",FeatName.c_str()); updateActive(); doCommand(Doc,str.str().c_str()); - doCommand(Doc,"App.activeDocument().%s.StdDirection = \"X\"", FeatName.c_str()); + Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(); + if (sketch) + doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])", + FeatName.c_str(), sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) @@ -1041,7 +1047,10 @@ void CmdPartDesignPolarPattern::activated(int iMsg) doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",FeatName.c_str()); updateActive(); doCommand(Doc,str.str().c_str()); - doCommand(Doc,"App.activeDocument().%s.StdAxis = \"X\"", FeatName.c_str()); + Part::Part2DObject *sketch = (static_cast(features.front()))->getVerifiedSketch(); + if (sketch) + doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])", + FeatName.c_str(), sketch->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 30e72df60e88..593550285d25 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -93,14 +93,14 @@ TaskLinearPatternParameters::TaskLinearPatternParameters(TaskMultiTransformParam void TaskLinearPatternParameters::setupUI() { + connect(ui->comboDirection, SIGNAL(activated(int)), + this, SLOT(onDirectionChanged(int))); connect(ui->checkReverse, SIGNAL(toggled(bool)), this, SLOT(onCheckReverse(bool))); connect(ui->spinLength, SIGNAL(valueChanged(double)), this, SLOT(onLength(double))); connect(ui->spinOccurrences, SIGNAL(valueChanged(int)), this, SLOT(onOccurrences(int))); - connect(ui->buttonReference, SIGNAL(toggled(bool)), - this, SLOT(onButtonReference(bool))); connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), this, SLOT(onUpdateView(bool))); @@ -119,14 +119,10 @@ void TaskLinearPatternParameters::setupUI() } // --------------------- - //ui->buttonX->setEnabled(true); - //ui->buttonY->setEnabled(true); - //ui->buttonZ->setEnabled(true); + ui->comboDirection->setEnabled(true); ui->checkReverse->setEnabled(true); ui->spinLength->setEnabled(true); ui->spinOccurrences->setEnabled(true); - ui->buttonReference->setEnabled(true); - ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only updateUI(); } @@ -140,35 +136,31 @@ void TaskLinearPatternParameters::updateUI() App::DocumentObject* directionFeature = pcLinearPattern->Direction.getValue(); std::vector directions = pcLinearPattern->Direction.getSubValues(); - std::string stdDirection = pcLinearPattern->StdDirection.getValue(); bool reverse = pcLinearPattern->Reversed.getValue(); double length = pcLinearPattern->Length.getValue(); unsigned occurrences = pcLinearPattern->Occurrences.getValue(); - ui->buttonReference->setChecked(referenceSelectionMode); - if (!stdDirection.empty()) - { - //ui->buttonX->setAutoExclusive(true); - //ui->buttonY->setAutoExclusive(true); - //ui->buttonZ->setAutoExclusive(true); - //ui->buttonX->setChecked(stdDirection == "X"); - //ui->buttonY->setChecked(stdDirection == "Y"); - //ui->buttonZ->setChecked(stdDirection == "Z"); - ui->lineReference->setText(tr("")); - } else if (directionFeature != NULL && !directions.empty()) { - //ui->buttonX->setAutoExclusive(false); - //ui->buttonY->setAutoExclusive(false); - //ui->buttonZ->setAutoExclusive(false); - //ui->buttonX->setChecked(false); - //ui->buttonY->setChecked(false); - //ui->buttonZ->setChecked(false); - ui->lineReference->setText(QString::fromAscii(directions.front().c_str())); + for (int i=ui->comboDirection->count()-1; i >= 2; i--) + ui->comboDirection->removeItem(i); + + if (directionFeature != NULL && !directions.empty()) { + if (directions.front() == "H_Axis") + ui->comboDirection->setCurrentIndex(0); + else if (directions.front() == "V_Axis") + ui->comboDirection->setCurrentIndex(1); + else if (directionFeature != NULL && !directions.empty()) { + ui->comboDirection->addItem(QString::fromAscii(directions.front().c_str())); + ui->comboDirection->setCurrentIndex(2); + } } else { // Error message? - ui->lineReference->setText(tr("")); } - if (referenceSelectionMode) - ui->lineReference->setText(tr("Select an edge or a face")); + + if (referenceSelectionMode) { + ui->comboDirection->addItem(tr("Select an edge or a face")); + ui->comboDirection->setCurrentIndex(ui->comboDirection->count() - 1); + } else + ui->comboDirection->addItem(tr("Select reference...")); // Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we // didn't check for blockUpdate @@ -201,31 +193,22 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); std::vector directions(1,subName); pcLinearPattern->Direction.setValue(getSupportObject(), directions); - pcLinearPattern->StdDirection.setValue(""); recomputeFeature(); updateUI(); } else { - ui->buttonReference->setChecked(referenceSelectionMode); - ui->lineReference->setText(QString::fromAscii(subName.c_str())); + for (int i=ui->comboDirection->count()-1; i >= 2; i--) + ui->comboDirection->removeItem(i); + + ui->comboDirection->addItem(QString::fromAscii(subName.c_str())); + ui->comboDirection->setCurrentIndex(2); + ui->comboDirection->addItem(tr("Select reference...")); } } } } -//void TaskLinearPatternParameters::onButtonX() { -// onStdDirection("X"); -//} -// -//void TaskLinearPatternParameters::onButtonY() { -// onStdDirection("Y"); -//} -// -//void TaskLinearPatternParameters::onButtonZ() { -// onStdDirection("Z"); -//} - void TaskLinearPatternParameters::onCheckReverse(const bool on) { if (blockUpdate) return; @@ -259,30 +242,32 @@ void TaskLinearPatternParameters::onOccurrences(const int n) { recomputeFeature(); } -void TaskLinearPatternParameters::onStdDirection(const std::string& dir) { +void TaskLinearPatternParameters::onDirectionChanged(int num) { if (blockUpdate) return; PartDesign::LinearPattern* pcLinearPattern = static_cast(getObject()); - pcLinearPattern->StdDirection.setValue(dir.c_str()); - pcLinearPattern->Direction.setValue(NULL); - - exitSelectionMode(); - updateUI(); - recomputeFeature(); -} -void TaskLinearPatternParameters::onButtonReference(bool checked) -{ - if (checked ) { + if (num == 0) { + pcLinearPattern->Direction.setValue(getSketchObject(), std::vector(1,"H_Axis")); + exitSelectionMode(); + } + else if (num == 1) { + pcLinearPattern->Direction.setValue(getSketchObject(), std::vector(1,"V_Axis")); + exitSelectionMode(); + } + else if (num == ui->comboDirection->count() - 1) { + // enter reference selection mode hideObject(); showOriginals(); referenceSelectionMode = true; Gui::Selection().clearSelection(); addReferenceSelectionGate(true, true); - } else { - exitSelectionMode(); } + else if (num == 2) + exitSelectionMode(); + updateUI(); + recomputeFeature(); } void TaskLinearPatternParameters::onUpdateView(bool on) @@ -295,16 +280,13 @@ void TaskLinearPatternParameters::onUpdateView(bool on) std::string direction = getDirection(); if (!direction.empty()) { std::vector directions(1,direction); - pcLinearPattern->Direction.setValue(getSupportObject(), directions); + if (direction == "H_Axis" || direction == "V_Axis") + pcLinearPattern->Direction.setValue(getSketchObject(), directions); + else + pcLinearPattern->Direction.setValue(getSupportObject(), directions); } else pcLinearPattern->Direction.setValue(NULL); - std::string stdDirection = getStdDirection(); - if (!stdDirection.empty()) - pcLinearPattern->StdDirection.setValue(stdDirection.c_str()); - else - pcLinearPattern->StdDirection.setValue(NULL); - pcLinearPattern->Reversed.setValue(getReverse()); pcLinearPattern->Length.setValue(getLength()); pcLinearPattern->Occurrences.setValue(getOccurrences()); @@ -313,20 +295,15 @@ void TaskLinearPatternParameters::onUpdateView(bool on) } } -const std::string TaskLinearPatternParameters::getStdDirection(void) const -{ - //if (ui->buttonX->isChecked()) - // return std::string("X"); - //else if (ui->buttonY->isChecked()) - // return std::string("Y"); - //else if (ui->buttonZ->isChecked()) - // return std::string("Z"); - return std::string(""); -} - const std::string TaskLinearPatternParameters::getDirection(void) const -{ - return ui->lineReference->text().toStdString(); +{ + if (ui->comboDirection->currentIndex() == 0) + return "H_Axis"; + else if (ui->comboDirection->currentIndex() == 1) + return "V_Axis"; + else if (ui->comboDirection->count() > 3 && ui->comboDirection->currentIndex() == 2) + return ui->comboDirection->currentText().toStdString(); + return std::string(""); } const bool TaskLinearPatternParameters::getReverse(void) const @@ -388,13 +365,14 @@ bool TaskDlgLinearPatternParameters::accept() std::string direction = linearpatternParameter->getDirection(); if (!direction.empty()) { QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSupportObject()->getNameInDocument())); + if (direction == "H_Axis" || direction == "V_Axis") + buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSketchObject()->getNameInDocument())); + else + buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSupportObject()->getNameInDocument())); buf = buf.arg(QString::fromUtf8(direction.c_str())); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str()); - std::string stdDirection = linearpatternParameter->getStdDirection(); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdDirection = \"%s\"",name.c_str(),stdDirection.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),linearpatternParameter->getReverse()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),linearpatternParameter->getLength()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),linearpatternParameter->getOccurrences()); diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.h b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.h index e3a88a779a7a..a76e9466836e 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.h +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.h @@ -56,21 +56,16 @@ class TaskLinearPatternParameters : public TaskTransformedParameters TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout); virtual ~TaskLinearPatternParameters(); - const std::string getStdDirection(void) const; const std::string getDirection(void) const; const bool getReverse(void) const; const double getLength(void) const; const unsigned getOccurrences(void) const; private Q_SLOTS: - void onStdDirection(const std::string& dir); - //void onButtonX(); - //void onButtonY(); - //void onButtonZ(); + void onDirectionChanged(int num); void onCheckReverse(const bool on); void onLength(const double l); void onOccurrences(const int n); - void onButtonReference(const bool checked); virtual void onUpdateView(bool); protected: diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.ui b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.ui index c6421af4cf4e..913e46eeb6e6 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.ui @@ -6,7 +6,7 @@ 0 0 - 225 + 260 402 @@ -31,17 +31,30 @@ - + Direction - - true - - + + + + Horizontal sketch axis + + + + + Vertical sketch axis + + + + + Select reference... + + + @@ -69,9 +82,6 @@ 999999.000000000000000 - - 5.000000000000000 - 100.000000000000000 diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index ec4dd414ec8c..f4945d91897e 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -93,14 +93,8 @@ TaskMirroredParameters::TaskMirroredParameters(TaskMultiTransformParameters *par void TaskMirroredParameters::setupUI() { - connect(ui->buttonXY, SIGNAL(pressed()), - this, SLOT(onButtonXY())); - connect(ui->buttonXZ, SIGNAL(pressed()), - this, SLOT(onButtonXZ())); - connect(ui->buttonYZ, SIGNAL(pressed()), - this, SLOT(onButtonYZ())); - connect(ui->buttonReference, SIGNAL(toggled(bool)), - this, SLOT(onButtonReference(bool))); + connect(ui->comboPlane, SIGNAL(activated(int)), + this, SLOT(onPlaneChanged(int))); connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), this, SLOT(onUpdateView(bool))); @@ -119,11 +113,7 @@ void TaskMirroredParameters::setupUI() } // --------------------- - ui->buttonXY->setEnabled(true); - ui->buttonXZ->setEnabled(true); - ui->buttonYZ->setEnabled(true); - ui->buttonReference->setEnabled(true); - ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only + ui->comboPlane->setEnabled(true); updateUI(); } @@ -132,35 +122,33 @@ void TaskMirroredParameters::updateUI() if (blockUpdate) return; blockUpdate = true; + PartDesign::Mirrored* pcMirrored = static_cast(getObject()); + App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue(); std::vector mirrorPlanes = pcMirrored->MirrorPlane.getSubValues(); - std::string stdMirrorPlane = pcMirrored->StdMirrorPlane.getValue(); - - ui->buttonReference->setChecked(referenceSelectionMode); - if (!stdMirrorPlane.empty()) - { - ui->buttonXY->setAutoExclusive(true); - ui->buttonXZ->setAutoExclusive(true); - ui->buttonYZ->setAutoExclusive(true); - ui->buttonXY->setChecked(stdMirrorPlane == "XY"); - ui->buttonXZ->setChecked(stdMirrorPlane == "XZ"); - ui->buttonYZ->setChecked(stdMirrorPlane == "YZ"); - ui->lineReference->setText(tr("")); - } else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { - ui->buttonXY->setAutoExclusive(false); - ui->buttonXZ->setAutoExclusive(false); - ui->buttonYZ->setAutoExclusive(false); - ui->buttonXY->setChecked(false); - ui->buttonXZ->setChecked(false); - ui->buttonYZ->setChecked(false); - ui->lineReference->setText(QString::fromAscii(mirrorPlanes.front().c_str())); + + for (int i=ui->comboPlane->count()-1; i >= 2; i--) + ui->comboPlane->removeItem(i); + + if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { + if (mirrorPlanes.front() == "H_Axis") + ui->comboPlane->setCurrentIndex(0); + else if (mirrorPlanes.front() == "V_Axis") + ui->comboPlane->setCurrentIndex(1); + else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) { + ui->comboPlane->addItem(QString::fromAscii(mirrorPlanes.front().c_str())); + ui->comboPlane->setCurrentIndex(2); + } } else { // Error message? - ui->lineReference->setText(tr("")); } - if (referenceSelectionMode) - ui->lineReference->setText(tr("Select a plane")); + + if (referenceSelectionMode) { + ui->comboPlane->addItem(tr("Select a face")); + ui->comboPlane->setCurrentIndex(ui->comboPlane->count() - 1); + } else + ui->comboPlane->addItem(tr("Select reference...")); blockUpdate = false; } @@ -186,55 +174,48 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg PartDesign::Mirrored* pcMirrored = static_cast(getObject()); std::vector mirrorPlanes(1,subName); pcMirrored->MirrorPlane.setValue(getSupportObject(), mirrorPlanes); - pcMirrored->StdMirrorPlane.setValue(""); recomputeFeature(); updateUI(); } else { - ui->buttonReference->setChecked(referenceSelectionMode); - ui->lineReference->setText(QString::fromAscii(subName.c_str())); + for (int i=ui->comboPlane->count()-1; i >= 2; i--) + ui->comboPlane->removeItem(i); + + ui->comboPlane->addItem(QString::fromAscii(subName.c_str())); + ui->comboPlane->setCurrentIndex(2); + ui->comboPlane->addItem(tr("Select reference...")); } } } } -void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) { +void TaskMirroredParameters::onPlaneChanged(int num) { if (blockUpdate) return; PartDesign::Mirrored* pcMirrored = static_cast(getObject()); - pcMirrored->StdMirrorPlane.setValue(plane.c_str()); - pcMirrored->MirrorPlane.setValue(NULL); - exitSelectionMode(); - updateUI(); - recomputeFeature(); -} - -void TaskMirroredParameters::onButtonXY() { - onStdMirrorPlane("XY"); -} - -void TaskMirroredParameters::onButtonXZ() { - onStdMirrorPlane("XZ"); -} - -void TaskMirroredParameters::onButtonYZ() { - onStdMirrorPlane("YZ"); -} - -void TaskMirroredParameters::onButtonReference(bool checked) -{ - if (checked ) { + if (num == 0) { + pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector(1,"H_Axis")); + exitSelectionMode(); + } + else if (num == 1) { + pcMirrored->MirrorPlane.setValue(getSketchObject(), std::vector(1,"V_Axis")); + exitSelectionMode(); + } + else if (num == ui->comboPlane->count() - 1) { + // enter reference selection mode hideObject(); showOriginals(); referenceSelectionMode = true; Gui::Selection().clearSelection(); addReferenceSelectionGate(false, true); - } else { - exitSelectionMode(); } + else if (num == 2) + exitSelectionMode(); + updateUI(); + recomputeFeature(); } void TaskMirroredParameters::onUpdateView(bool on) @@ -247,37 +228,28 @@ void TaskMirroredParameters::onUpdateView(bool on) std::string mirrorPlane = getMirrorPlane(); if (!mirrorPlane.empty()) { std::vector planes(1,mirrorPlane); - pcMirrored->MirrorPlane.setValue(getSupportObject(),planes); + if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis") + pcMirrored->MirrorPlane.setValue(getSketchObject(),planes); + else + pcMirrored->MirrorPlane.setValue(getSupportObject(),planes); } else pcMirrored->MirrorPlane.setValue(NULL); - std::string stdMirrorPlane = getStdMirrorPlane(); - if (!stdMirrorPlane.empty()) - pcMirrored->StdMirrorPlane.setValue(stdMirrorPlane.c_str()); - else - pcMirrored->StdMirrorPlane.setValue(NULL); - recomputeFeature(); } } -const std::string TaskMirroredParameters::getStdMirrorPlane(void) const -{ - if (ui->buttonXY->isChecked()) - return std::string("XY"); - else if (ui->buttonYZ->isChecked()) - return std::string("YZ"); - else if (ui->buttonXZ->isChecked()) - return std::string("XZ"); - return std::string(""); -} - const std::string TaskMirroredParameters::getMirrorPlane(void) const { - return ui->lineReference->text().toStdString(); + if (ui->comboPlane->currentIndex() == 0) + return "H_Axis"; + else if (ui->comboPlane->currentIndex() == 1) + return "V_Axis"; + else if (ui->comboPlane->count() > 3 && ui->comboPlane->currentIndex() == 2) + return ui->comboPlane->currentText().toStdString(); + return std::string(""); } - TaskMirroredParameters::~TaskMirroredParameters() { delete ui; @@ -321,13 +293,14 @@ bool TaskDlgMirroredParameters::accept() std::string mirrorPlane = mirrorParameter->getMirrorPlane(); if (!mirrorPlane.empty()) { QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument())); + if (mirrorPlane == "H_Axis" || mirrorPlane == "V_Axis") + buf = buf.arg(QString::fromUtf8(mirrorParameter->getSketchObject()->getNameInDocument())); + else + buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument())); buf = buf.arg(QString::fromUtf8(mirrorPlane.c_str())); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), buf.toStdString().c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str()); - std::string stdMirrorPlane = mirrorParameter->getStdMirrorPlane(); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdMirrorPlane = \"%s\"",name.c_str(),stdMirrorPlane.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); if (!TransformedView->getObject()->isValid()) throw Base::Exception(TransformedView->getObject()->getStatusString()); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.h b/src/Mod/PartDesign/Gui/TaskMirroredParameters.h index ec9fd210f44a..916c0c8f866f 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.h +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.h @@ -57,14 +57,10 @@ class TaskMirroredParameters : public TaskTransformedParameters virtual ~TaskMirroredParameters(); - const std::string getStdMirrorPlane(void) const; const std::string getMirrorPlane(void) const; private Q_SLOTS: - void onButtonXY(); - void onButtonXZ(); - void onButtonYZ(); - void onButtonReference(const bool checked); + void onPlaneChanged(int num); virtual void onUpdateView(bool); protected: @@ -72,7 +68,6 @@ private Q_SLOTS: virtual void onSelectionChanged(const Gui::SelectionChanges& msg); private: - void onStdMirrorPlane(const std::string& plane); void setupUI(); void updateUI(); diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.ui b/src/Mod/PartDesign/Gui/TaskMirroredParameters.ui index c34a29d170d2..f0f2e8d7d789 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.ui @@ -28,48 +28,33 @@ - - - - - - XY - - - true - - - - - - - XZ - - - - - - - YZ - - - - - - + Plane - - true - - + + + + Horizontal sketch axis + + + + + Vertical sketch axis + + + + + Select reference... + + + diff --git a/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp b/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp index c581054fd941..fcad5116cd79 100644 --- a/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp @@ -218,7 +218,10 @@ void TaskMultiTransformParameters::onTransformAddMirrored() Gui::Command::openCommand("Mirrored"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",newFeatName.c_str()); //Gui::Command::updateActive(); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdMirrorPlane = \"XY\"", newFeatName.c_str()); + App::DocumentObject* sketch = getSketchObject(); + if (sketch) + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])", + newFeatName.c_str(), sketch->getNameInDocument()); finishAdd(newFeatName); } @@ -231,7 +234,10 @@ void TaskMultiTransformParameters::onTransformAddLinearPattern() Gui::Command::openCommand("LinearPattern"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",newFeatName.c_str()); //Gui::Command::updateActive(); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdDirection = \"X\"", newFeatName.c_str()); + App::DocumentObject* sketch = getSketchObject(); + if (sketch) + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])", + newFeatName.c_str(), sketch->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Length = 100", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str()); @@ -246,7 +252,10 @@ void TaskMultiTransformParameters::onTransformAddPolarPattern() Gui::Command::openCommand("PolarPattern"); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",newFeatName.c_str()); //Gui::Command::updateActive(); - Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdAxis = \"X\"", newFeatName.c_str()); + App::DocumentObject* sketch = getSketchObject(); + if (sketch) + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])", + newFeatName.c_str(), sketch->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Angle = 360", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str()); diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index 0c5e0750a21a..e63051a7b7b5 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -93,20 +93,14 @@ TaskPolarPatternParameters::TaskPolarPatternParameters(TaskMultiTransformParamet void TaskPolarPatternParameters::setupUI() { - connect(ui->buttonX, SIGNAL(pressed()), - this, SLOT(onButtonX())); - connect(ui->buttonY, SIGNAL(pressed()), - this, SLOT(onButtonY())); - connect(ui->buttonZ, SIGNAL(pressed()), - this, SLOT(onButtonZ())); + connect(ui->comboAxis, SIGNAL(activated(int)), + this, SLOT(onAxisChanged(int))); connect(ui->checkReverse, SIGNAL(toggled(bool)), this, SLOT(onCheckReverse(bool))); connect(ui->spinAngle, SIGNAL(valueChanged(double)), this, SLOT(onAngle(double))); connect(ui->spinOccurrences, SIGNAL(valueChanged(int)), this, SLOT(onOccurrences(int))); - connect(ui->buttonReference, SIGNAL(toggled(bool)), - this, SLOT(onButtonReference(bool))); connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), this, SLOT(onUpdateView(bool))); @@ -125,14 +119,10 @@ void TaskPolarPatternParameters::setupUI() } // --------------------- - ui->buttonX->setEnabled(true); - ui->buttonY->setEnabled(true); - ui->buttonZ->setEnabled(true); + ui->comboAxis->setEnabled(true); ui->checkReverse->setEnabled(true); ui->spinAngle->setEnabled(true); ui->spinOccurrences->setEnabled(true); - ui->buttonReference->setEnabled(true); - ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only updateUI(); } @@ -146,36 +136,32 @@ void TaskPolarPatternParameters::updateUI() App::DocumentObject* axisFeature = pcPolarPattern->Axis.getValue(); std::vector axes = pcPolarPattern->Axis.getSubValues(); - std::string stdAxis = pcPolarPattern->StdAxis.getValue(); bool reverse = pcPolarPattern->Reversed.getValue(); double angle = pcPolarPattern->Angle.getValue(); unsigned occurrences = pcPolarPattern->Occurrences.getValue(); - ui->buttonReference->setChecked(referenceSelectionMode); - if (!stdAxis.empty()) - { - ui->buttonX->setAutoExclusive(true); - ui->buttonY->setAutoExclusive(true); - ui->buttonZ->setAutoExclusive(true); - ui->buttonX->setChecked(stdAxis == "X"); - ui->buttonY->setChecked(stdAxis == "Y"); - ui->buttonZ->setChecked(stdAxis == "Z"); - ui->lineReference->setText(tr("")); - } else if (axisFeature != NULL && !axes.empty()) { - ui->buttonX->setAutoExclusive(false); - ui->buttonY->setAutoExclusive(false); - ui->buttonZ->setAutoExclusive(false); - ui->buttonX->setChecked(false); - ui->buttonY->setChecked(false); - ui->buttonZ->setChecked(false); - ui->lineReference->setText(QString::fromAscii(axes.front().c_str())); + for (int i=ui->comboAxis->count()-1; i >= 1; i--) + ui->comboAxis->removeItem(i); + + if (axisFeature != NULL && !axes.empty()) { + if (axes.front() == "N_Axis") + ui->comboAxis->setCurrentIndex(0); + else if (axisFeature != NULL && !axes.empty()) { + ui->comboAxis->addItem(QString::fromAscii(axes.front().c_str())); + ui->comboAxis->setCurrentIndex(1); + } } else { // Error message? - ui->lineReference->setText(tr("")); } - if (referenceSelectionMode) - ui->lineReference->setText(tr("Select an edge")); + if (referenceSelectionMode) { + ui->comboAxis->addItem(tr("Select an edge")); + ui->comboAxis->setCurrentIndex(ui->comboAxis->count() - 1); + } else + ui->comboAxis->addItem(tr("Select reference...")); + + // Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we + // didn't check for blockUpdate ui->checkReverse->setChecked(reverse); ui->spinAngle->setValue(angle); ui->spinOccurrences->setValue(occurrences); @@ -204,31 +190,22 @@ void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& PartDesign::PolarPattern* pcPolarPattern = static_cast(getObject()); std::vector axes(1,subName); pcPolarPattern->Axis.setValue(getSupportObject(), axes); - pcPolarPattern->StdAxis.setValue(""); recomputeFeature(); updateUI(); } else { - ui->buttonReference->setChecked(referenceSelectionMode); - ui->lineReference->setText(QString::fromAscii(subName.c_str())); + for (int i=ui->comboAxis->count()-1; i >= 1; i--) + ui->comboAxis->removeItem(i); + + ui->comboAxis->addItem(QString::fromAscii(subName.c_str())); + ui->comboAxis->setCurrentIndex(1); + ui->comboAxis->addItem(tr("Select reference...")); } } } } -void TaskPolarPatternParameters::onButtonX() { - onStdAxis("X"); -} - -void TaskPolarPatternParameters::onButtonY() { - onStdAxis("Y"); -} - -void TaskPolarPatternParameters::onButtonZ() { - onStdAxis("Z"); -} - void TaskPolarPatternParameters::onCheckReverse(const bool on) { if (blockUpdate) return; @@ -262,30 +239,28 @@ void TaskPolarPatternParameters::onOccurrences(const int n) { recomputeFeature(); } -void TaskPolarPatternParameters::onStdAxis(const std::string& axis) { +void TaskPolarPatternParameters::onAxisChanged(int num) { if (blockUpdate) return; PartDesign::PolarPattern* pcPolarPattern = static_cast(getObject()); - pcPolarPattern->StdAxis.setValue(axis.c_str()); - pcPolarPattern->Axis.setValue(NULL); - exitSelectionMode(); - updateUI(); - recomputeFeature(); -} - -void TaskPolarPatternParameters::onButtonReference(bool checked) -{ - if (checked ) { + if (num == 0) { + pcPolarPattern->Axis.setValue(getSketchObject(), std::vector(1,"N_Axis")); + exitSelectionMode(); + } + else if (num == ui->comboAxis->count() - 1) { + // enter reference selection mode hideObject(); showOriginals(); referenceSelectionMode = true; Gui::Selection().clearSelection(); addReferenceSelectionGate(true, false); - } else { - exitSelectionMode(); } + else if (num == 1) + exitSelectionMode(); + updateUI(); + recomputeFeature(); } void TaskPolarPatternParameters::onUpdateView(bool on) @@ -298,16 +273,13 @@ void TaskPolarPatternParameters::onUpdateView(bool on) std::string axis = getAxis(); if (!axis.empty()) { std::vector axes(1,axis); - pcPolarPattern->Axis.setValue(getSupportObject(),axes); + if (axis == "N_Axis") + pcPolarPattern->Axis.setValue(getSketchObject(), axes); + else + pcPolarPattern->Axis.setValue(getSupportObject(), axes); } else pcPolarPattern->Axis.setValue(NULL); - std::string stdAxis = getStdAxis(); - if (!stdAxis.empty()) - pcPolarPattern->StdAxis.setValue(stdAxis.c_str()); - else - pcPolarPattern->StdAxis.setValue(NULL); - pcPolarPattern->Reversed.setValue(getReverse()); pcPolarPattern->Angle.setValue(getAngle()); pcPolarPattern->Occurrences.setValue(getOccurrences()); @@ -316,22 +288,15 @@ void TaskPolarPatternParameters::onUpdateView(bool on) } } -const std::string TaskPolarPatternParameters::getStdAxis(void) const +const std::string TaskPolarPatternParameters::getAxis(void) const { - if (ui->buttonX->isChecked()) - return std::string("X"); - else if (ui->buttonY->isChecked()) - return std::string("Y"); - else if (ui->buttonZ->isChecked()) - return std::string("Z"); + if (ui->comboAxis->currentIndex() == 0) + return "N_Axis"; + else if (ui->comboAxis->count() > 2 && ui->comboAxis->currentIndex() == 1) + return ui->comboAxis->currentText().toStdString(); return std::string(""); } -const std::string TaskPolarPatternParameters::getAxis(void) const -{ - return ui->lineReference->text().toStdString(); -} - const bool TaskPolarPatternParameters::getReverse(void) const { return ui->checkReverse->isChecked(); @@ -391,13 +356,14 @@ bool TaskDlgPolarPatternParameters::accept() std::string axis = polarpatternParameter->getAxis(); if (!axis.empty()) { QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(polarpatternParameter->getSupportObject()->getNameInDocument())); + if (axis == "N_Axis") + buf = buf.arg(QString::fromUtf8(polarpatternParameter->getSketchObject()->getNameInDocument())); + else + buf = buf.arg(QString::fromUtf8(polarpatternParameter->getSupportObject()->getNameInDocument())); buf = buf.arg(QString::fromUtf8(axis.c_str())); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), buf.toStdString().c_str()); } else Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str()); - std::string stdAxis = polarpatternParameter->getStdAxis(); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdAxis = \"%s\"",name.c_str(),stdAxis.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),polarpatternParameter->getReverse()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),polarpatternParameter->getAngle()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),polarpatternParameter->getOccurrences()); diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.h b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.h index 6b06f10a61a7..9d23bebffcc9 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.h @@ -63,14 +63,10 @@ class TaskPolarPatternParameters : public TaskTransformedParameters const unsigned getOccurrences(void) const; private Q_SLOTS: - void onStdAxis(const std::string& axis); - void onButtonX(); - void onButtonY(); - void onButtonZ(); + void onAxisChanged(int num); void onCheckReverse(const bool on); void onAngle(const double a); void onOccurrences(const int n); - void onButtonReference(const bool checked); virtual void onUpdateView(bool); protected: diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.ui b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.ui index a5ad73322d36..2918f4ac082f 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.ui @@ -28,48 +28,28 @@ - - - - - - X - - - true - - - - - - - Y - - - - - - - Z - - - - - - + - Direction - - - true + Axis - + + + + Normal sketch axis + + + + + Select reference... + + + diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index f13165768bcc..129b6276b682 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -148,6 +148,16 @@ App::DocumentObject* TaskTransformedParameters::getSupportObject() const } } +App::DocumentObject* TaskTransformedParameters::getSketchObject() const +{ + if (insideMultiTransform) { + return parentTask->getSketchObject(); + } else { + PartDesign::Transformed* pcTransformed = static_cast(TransformedView->getObject()); + return pcTransformed->getSketchObject(); + } +} + void TaskTransformedParameters::hideObject() { Gui::Document* doc = Gui::Application::Instance->activeDocument(); diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h index e50610497dcd..68bd60f8e880 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.h @@ -61,7 +61,8 @@ class TaskTransformedParameters : public Gui::TaskView::TaskBox, public Gui::Sel const std::vector getOriginals(void) const; /// Get the support object either of the object associated with this feature or with the parent feature (MultiTransform mode) App::DocumentObject* getSupportObject() const; - + /// Get the sketch object of the first original either of the object associated with this feature or with the parent feature (MultiTransform mode) + App::DocumentObject* getSketchObject() const; protected Q_SLOTS: /// Connect the subTask OK button to the MultiTransform task diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1f1278d13d9e..2e972531e8dc 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -274,14 +274,10 @@ int SketchObject::getAxisCount(void) const Base::Axis SketchObject::getAxis(int axId) const { - const std::vector< Part::Geometry * > &vals = getInternalGeometry(); - if (axId == H_Axis) { - return Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(1,0,0)); - } - else if (axId == V_Axis) { - return Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,1,0)); - } + if (axId == H_Axis || axId == V_Axis || axId == N_Axis) + return Part::Part2DObject::getAxis(axId); + const std::vector< Part::Geometry * > &vals = getInternalGeometry(); int count=0; for (std::vector::const_iterator geo=vals.begin(); geo != vals.end(); geo++)