From 94b6b8961087e2d85a9f66d9fd843c5e735e6b34 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Sat, 30 Mar 2013 14:33:06 +0430 Subject: [PATCH] Enhanced Pick dialog for PartDesign feature's sketches --- src/Mod/PartDesign/App/Body.cpp | 2 +- src/Mod/PartDesign/App/Body.h | 2 +- src/Mod/PartDesign/Gui/Command.cpp | 123 +- src/Mod/PartDesign/Gui/Command.cpp.orig | 1610 +---------------- src/Mod/PartDesign/Gui/FeaturePickDialog.cpp | 96 +- .../PartDesign/Gui/FeaturePickDialog.cpp.orig | 166 ++ src/Mod/PartDesign/Gui/FeaturePickDialog.h | 18 +- src/Mod/PartDesign/Gui/FeaturePickDialog.ui | 39 +- src/Mod/PartDesign/Gui/TaskPadParameters.cpp | 9 +- 9 files changed, 467 insertions(+), 1598 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/FeaturePickDialog.cpp.orig diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index c255f8715..27af6aada 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -86,7 +86,7 @@ const Part::TopoShape Body::getPreviousSolid(const PartDesign::Feature* f) return static_cast(*it)->Shape.getShape(); } -const bool Body::hasFeature(const PartDesign::Feature* f) +const bool Body::hasFeature(const App::DocumentObject* f) { std::vector features = Model.getValues(); return std::find(features.begin(), features.end(), f) != features.end(); diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index ffc46a517..074bb0e73 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -58,7 +58,7 @@ public: const Part::TopoShape getPreviousSolid(const PartDesign::Feature* f); /// Return true if the feature belongs to this body - const bool hasFeature(const PartDesign::Feature* f); + const bool hasFeature(const App::DocumentObject *f); PyObject *getPyObject(void); diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 4d26f1473..4537692e0 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -81,7 +81,6 @@ PartDesign::Body *getBody(void) } - //=========================================================================== // PartDesign_Sketch //=========================================================================== @@ -217,37 +216,46 @@ bool CmdPartDesignNewSketch::isActive(void) //=========================================================================== // Take a list of Part2DObjects and erase those which are not eligible for creating a -// SketchBased feature. If supportRequired is true, also erase those that cannot be used to define -// a Subtractive feature -void validateSketches(std::vector& sketches, const bool supportRequired) -{ - std::vector::iterator s = sketches.begin(); +// SketchBased feature. + const unsigned validateSketches(std::vector& sketches, + std::vector& status, + std::vector::iterator& firstValidSketch) +{ + // TODO: If the user previously opted to allow multiple use of sketches or use of sketches from other bodies, + // then count these as valid sketches! + unsigned validSketches = 0; + firstValidSketch = sketches.end(); - while (s != sketches.end()) { - // sketch is always part of the body first. - //// Check whether this sketch is already being used by another feature - //std::vector ref = (*s)->getInList(); - //std::vector::iterator r = ref.begin(); - //while (r != ref.end()) { - // if (!(*r)->getTypeId().isDerivedFrom(PartDesign::SketchBased().getClassTypeId())) { - // r = ref.erase(r); - // continue; - // } - // ++r; - //} - //if (!ref.empty()) { - // // TODO: Display some information message that this sketch was removed? - // s = sketches.erase(s); - // continue; - //} + for (std::vector::iterator s = sketches.begin(); s != sketches.end(); s++) { + // Check whether this sketch is already being used by another feature + // Body features don't count... + std::vector inList = (*s)->getInList(); + std::vector::iterator o = inList.begin(); + while (o != inList.end()) { + Base::Console().Error("InList: %s\n", (*o)->getNameInDocument()); + if ((*o)->getTypeId().isDerivedFrom(PartDesign::Body::getClassTypeId())) + o = inList.erase(o); + else + ++o; + } + if (inList.size() > 0) { + status.push_back(PartDesignGui::FeaturePickDialog::isUsed); + continue; + } + + // Check whether this sketch belongs to the active body + PartDesign::Body* body = getBody(); + if (!body->hasFeature(*s)) { + status.push_back(PartDesignGui::FeaturePickDialog::otherBody); + continue; + } // Check whether the sketch shape is valid Part::Part2DObject* sketch = static_cast(*s); const TopoDS_Shape& shape = sketch->Shape.getValue(); if (shape.IsNull()) { - s = sketches.erase(s); + status.push_back(PartDesignGui::FeaturePickDialog::invalidShape); continue; - // TODO: Display some information message that this sketch was removed? } // count free wires @@ -257,24 +265,18 @@ void validateSketches(std::vector& sketches, const bool su ctWires++; } if (ctWires == 0) { - s = sketches.erase(s); + status.push_back(PartDesignGui::FeaturePickDialog::noWire); continue; - // TODO: Display some information message that this sketch was removed? } - // Check for support - if (supportRequired) { - App::DocumentObject* support = sketch->Support.getValue(); - if (support == NULL) { - s = sketches.erase(s); - continue; - // TODO: Display some information message that this sketch was removed? - } - } - - // All checks passed - go on to next candidate - s++; + // All checks passed - found a valid sketch + if (firstValidSketch == sketches.end()) + firstValidSketch = s; + validSketches++; + status.push_back(PartDesignGui::FeaturePickDialog::validFeature); } + + return validSketches; } void prepareSketchBased(Gui::Command* cmd, const std::string& which, @@ -283,35 +285,33 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, PartDesign::Body *pcActiveBody = getBody(); if (!pcActiveBody) return; - bool bNoSketchWasSelected = false; // Get a valid sketch from the user // First check selections + FeatName = ""; // Empty string means prepareSketchBased() was not successful + std::vector status; + std::vector::iterator firstValidSketch; std::vector sketches = cmd->getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - validateSketches(sketches, false); - // Next let the user choose from a list of all eligible objects - if (sketches.size() == 0) { + // Next let the user choose from a list of all eligible objects + unsigned validSketches = validateSketches(sketches, status, firstValidSketch); + if (validSketches == 0) { + status.clear(); sketches = cmd->getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); - bNoSketchWasSelected = true; - } - if (sketches.size() == 0) { - if (bNoSketchWasSelected) { + validSketches = validateSketches(sketches, status, firstValidSketch); + if (validSketches == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), QObject::tr("Please create a sketch or 2D object first.")); - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches selected"), - QObject::tr("None of selected sketches/2D objects is valid for padding. Please select a valid sketch or 2D object that is not used by any other feature.")); + return; } - return; } - // If there is more than one selection/possibility, show dialog and let user pick sketch - if (sketches.size() > 1) { - PartDesignGui::FeaturePickDialog Dlg(sketches); + if (validSketches > 1) { + PartDesignGui::FeaturePickDialog Dlg(sketches, status); if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) return; // Cancelled or nothing selected + firstValidSketch = sketches.begin(); } - sketch = static_cast(sketches.front()); + sketch = static_cast(*firstValidSketch); FeatName = cmd->getUniqueObjectName(which.c_str()); cmd->openCommand((std::string("Make ") + which).c_str()); @@ -323,7 +323,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch, const std::string& FeatName) { - App::DocumentObjectGroup* grp = sketch->getGroup(); + App::DocumentObjectGroup* grp = sketch->getGroup(); if (grp) { cmd->doCommand(cmd->Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" ,grp->getNameInDocument(),FeatName.c_str()); @@ -334,18 +334,17 @@ void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch cmd->updateActive(); if (cmd->isActiveObjectValid()) { cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument()); - } + } // #0001721: use '0' as edit value to avoid switching off selection in // ViewProviderGeometryObject::setEditViewer - cmd->doCommand(cmd->Gui,"Gui.activeDocument().setEdit('%s', 0)", FeatName.c_str()); + cmd->doCommand(cmd->Gui,"Gui.activeDocument().setEdit('%s', 0)", FeatName.c_str()); - /* PartDesign::Body *pcActiveBody = getBody(); if (pcActiveBody) { cmd->copyVisual(FeatName.c_str(), "ShapeColor", pcActiveBody->getNameInDocument()); cmd->copyVisual(FeatName.c_str(), "LineColor", pcActiveBody->getNameInDocument()); cmd->copyVisual(FeatName.c_str(), "PointColor", pcActiveBody->getNameInDocument()); - }*/ + } } //=========================================================================== @@ -370,6 +369,7 @@ void CmdPartDesignPad::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Pad", sketch, FeatName); + if (FeatName.empty()) return; // specific parameters for Pad doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); @@ -405,6 +405,7 @@ void CmdPartDesignPocket::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Pocket", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str()); @@ -439,6 +440,7 @@ void CmdPartDesignRevolution::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Revolution", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", FeatName.c_str(), sketch->getNameInDocument()); @@ -478,6 +480,7 @@ void CmdPartDesignGroove::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Groove", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", FeatName.c_str(), sketch->getNameInDocument()); diff --git a/src/Mod/PartDesign/Gui/Command.cpp.orig b/src/Mod/PartDesign/Gui/Command.cpp.orig index f89af8a92..c007b284c 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp.orig +++ b/src/Mod/PartDesign/Gui/Command.cpp.orig @@ -1,1444 +1,3 @@ -<<<<<<< ac24729340fa24c813f627f5e72fa487a8b4e5f9 -/*************************************************************************** - * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "FeaturePickDialog.h" - -using namespace std; - -extern PartDesign::Body *ActivePartObject; - -namespace Gui { -//=========================================================================== -// Common utility functions -//=========================================================================== - -// Take a list of Part2DObjects and erase those which are not eligible for creating a -// SketchBased feature. If supportRequired is true, also erase those that cannot be used to define -// a Subtractive feature -void validateSketches(std::vector& sketches, const bool supportRequired) -{ - std::vector::iterator s = sketches.begin(); - - while (s != sketches.end()) { - // sketch is allways part of the body first. - //// Check whether this sketch is already being used by another feature - //std::vector ref = (*s)->getInList(); - //std::vector::iterator r = ref.begin(); - //while (r != ref.end()) { - // if (!(*r)->getTypeId().isDerivedFrom(PartDesign::SketchBased().getClassTypeId())) { - // r = ref.erase(r); - // continue; - // } - // ++r; - //} - //if (!ref.empty()) { - // // TODO: Display some information message that this sketch was removed? - // s = sketches.erase(s); - // continue; - //} - - // Check whether the sketch shape is valid - Part::Part2DObject* sketch = static_cast(*s); - const TopoDS_Shape& shape = sketch->Shape.getValue(); - if (shape.IsNull()) { - s = sketches.erase(s); - continue; - // TODO: Display some information message that this sketch was removed? - } - - // count free wires - int ctWires=0; - TopExp_Explorer ex; - for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) { - ctWires++; - } - if (ctWires == 0) { - s = sketches.erase(s); - continue; - // TODO: Display some information message that this sketch was removed? - } - - // Check for support - if (supportRequired) { - App::DocumentObject* support = sketch->Support.getValue(); - if (support == NULL) { - s = sketches.erase(s); - continue; - // TODO: Display some information message that this sketch was removed? - } - } - - // All checks passed - go on to next candidate - s++; - } -} -} // namespace Gui - -//=========================================================================== -// Helper for Body -//=========================================================================== - -PartDesign::Body *getBody(void) -{ - if(!ActivePartObject){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), - QObject::tr("To do PartDesign you need a active Body object in the documnt. Please make one active or create one. If you have a document with PartDesign objects without Body, use the transfer methode in PartDesign to put it into a Body.")); - } - return ActivePartObject; - -} - - -//=========================================================================== -// Part_Pad -//=========================================================================== - -/* Sketch commands =======================================================*/ -DEF_STD_CMD_A(CmdPartDesignNewSketch); - -CmdPartDesignNewSketch::CmdPartDesignNewSketch() - :Command("PartDesign_NewSketch") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Create sketch"); - sToolTipText = QT_TR_NOOP("Create a new sketch"); - sWhatsThis = sToolTipText; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_NewSketch"; -} - - -void CmdPartDesignNewSketch::activated(int iMsg) -{ - PartDesign::Body *pcActiveBody = getBody(); - - // No PartDesign feature without Body past FreeCAD 0.13 - if(!pcActiveBody) return; - - Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1"); - Gui::SelectionFilter FaceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1"); - - if (SketchFilter.match()) { - Sketcher::SketchObject *Sketch = static_cast(SketchFilter.Result[0][0].getObject()); - openCommand("Edit Sketch"); - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Sketch->getNameInDocument()); - } - else if (FaceFilter.match()) { - // get the selected object - Part::Feature *part = static_cast(FaceFilter.Result[0][0].getObject()); - Base::Placement ObjectPos = part->Placement.getValue(); - const std::vector &sub = FaceFilter.Result[0][0].getSubNames(); - if (sub.size() > 1){ - // No assert for wrong user input! - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Several sub-elements selected"), - QObject::tr("You have to select a single face as support for a sketch!")); - return; - } - // get the selected sub shape (a Face) - const Part::TopoShape &shape = part->Shape.getValue(); - TopoDS_Shape sh = shape.getSubShape(sub[0].c_str()); - const TopoDS_Face& face = TopoDS::Face(sh); - if (face.IsNull()){ - // No assert for wrong user input! - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No support face selected"), - QObject::tr("You have to select a face as support for a sketch!")); - return; - } - - BRepAdaptor_Surface adapt(face); - if (adapt.GetType() != GeomAbs_Plane){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No planar support"), - QObject::tr("You need a planar face as support for a sketch!")); - return; - } - - std::string supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString(); - - // create Sketch on Face - std::string FeatName = getUniqueObjectName("Sketch"); - - openCommand("Create a Sketch on Face"); - doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Model + [App.activeDocument().%s]",pcActiveBody->getNameInDocument(),pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Gui,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str()); - doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support - //doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str()); - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - } - else { - // ask user for orientation - SketcherGui::SketchOrientationDialog Dlg; - - if (Dlg.exec() != QDialog::Accepted) - return; // canceled - Base::Vector3d p = Dlg.Pos.getPosition(); - Base::Rotation r = Dlg.Pos.getRotation(); - - // do the right view direction - std::string camstring; - switch(Dlg.DirType){ - case 0: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n position 0 0 87 \\n orientation 0 0 1 0 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; - break; - case 1: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA \\n position 0 0 -87 \\n orientation -1 0 0 3.1415927 \\n nearDistance -112.88701 \\n farDistance 287.28702 \\n aspectRatio 1 \\n focalDistance 87 \\n height 143.52005 }"; - break; - case 2: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 0 -87 0 \\n orientation -1 0 0 4.712389\\n nearDistance -112.88701\\n farDistance 287.28702\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; - break; - case 3: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 0 87 0 \\n orientation 0 0.70710683 0.70710683 3.1415927\\n nearDistance -112.88701\\n farDistance 287.28702\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; - break; - case 4: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position 87 0 0 \\n orientation 0.57735026 0.57735026 0.57735026 2.0943952 \\n nearDistance -112.887\\n farDistance 287.28699\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; - break; - case 5: - camstring = "#Inventor V2.1 ascii \\n OrthographicCamera {\\n viewportMapping ADJUST_CAMERA\\n position -87 0 0 \\n orientation -0.57735026 0.57735026 0.57735026 4.1887903 \\n nearDistance -112.887\\n farDistance 287.28699\\n aspectRatio 1\\n focalDistance 87\\n height 143.52005\\n\\n}"; - break; - } - std::string FeatName = getUniqueObjectName("Sketch"); - - openCommand("Create a new Sketch"); - doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",FeatName.c_str(),p.x,p.y,p.z,r[0],r[1],r[2],r[3]); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Model + [App.activeDocument().%s]",pcActiveBody->getNameInDocument(),pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",camstring.c_str()); - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - } - -} - -bool CmdPartDesignNewSketch::isActive(void) -{ - if (getActiveGuiDocument()) - return true; - else - return false; -} - -//=========================================================================== -// PartDesign_Pad -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignPad); - -CmdPartDesignPad::CmdPartDesignPad() - : Command("PartDesign_Pad") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Pad"); - sToolTipText = QT_TR_NOOP("Pad a selected sketch"); - sWhatsThis = "PartDesign_Pad"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Pad"; -} - -void CmdPartDesignPad::activated(int iMsg) -{ - PartDesign::Body *pcActiveBody = getBody(); - - bool bNoSketchWasSelected = false; - // Get a valid sketch from the user - // First check selections - std::vector sketches = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - if (sketches.size() == 0) {//no sketches were selected. Let user pick an object from valid ones available in document - sketches = getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); - bNoSketchWasSelected = true; - } - Gui::validateSketches(sketches, false); - if (sketches.size() == 0) { - if (bNoSketchWasSelected) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), - QObject::tr("Please create a sketch or 2D object first.")); - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches selected"), - QObject::tr("None of selected sketches/2D objects is valid for padding. Please select a valid sketch or 2D object that is not used by any other feature.")); - } - return; - } - - // If there is more than one selection/possibility, show dialog and let user pick sketch - if (sketches.size() > 1) { - PartDesignGui::FeaturePickDialog Dlg(sketches); - if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) - return; // Cancelled or nothing selected - } - - Part::Part2DObject* sketch = static_cast(sketches.front()); - App::DocumentObject* support = sketch->Support.getValue(); - std::string FeatName = getUniqueObjectName("Pad"); - - openCommand("Make Pad"); - doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pad\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Model + [App.activeDocument().%s]",pcActiveBody->getNameInDocument(),pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); - App::DocumentObjectGroup* grp = sketch->getGroup(); - if (grp) { - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),sketch->getNameInDocument()); - } - updateActive(); - if (isActiveObjectValid()) { - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); - if (support) - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); - } - // #0001721: use '0' as edit value to avoid switching off selection in - // ViewProviderGeometryObject::setEditViewer - doCommand(Gui,"Gui.activeDocument().setEdit('%s',0)",FeatName.c_str()); - - //commitCommand(); - adjustCameraPosition(); - - if (support) { - copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument()); - } -} - -bool CmdPartDesignPad::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Pocket -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignPocket); - -CmdPartDesignPocket::CmdPartDesignPocket() - : Command("PartDesign_Pocket") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Pocket"); - sToolTipText = QT_TR_NOOP("Create a pocket with the selected sketch"); - sWhatsThis = "PartDesign_Pocket"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Pocket"; -} - -void CmdPartDesignPocket::activated(int iMsg) -{ - PartDesign::Body *pcActiveBody = getBody(); - - // Get a valid sketch from the user - // First check selections - std::vector sketches = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - Gui::validateSketches(sketches, true); - // Next let the user choose from a list of all eligible objects - if (sketches.size() == 0) { - sketches = getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); - Gui::validateSketches(sketches, true); - if (sketches.size() == 0) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), - QObject::tr("Please create a sketch or 2D object first. It must have a support face on a solid.")); - return; - } - } - // If there is more than one selection/possibility, show dialog and let user pick sketch - if (sketches.size() > 1) { - PartDesignGui::FeaturePickDialog Dlg(sketches); - if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) - return; // Cancelled or nothing selected - } - - Part::Part2DObject* sketch = static_cast(sketches.front()); - App::DocumentObject* support = sketch->Support.getValue(); - std::string FeatName = getUniqueObjectName("Pocket"); - - openCommand("Make Pocket"); - doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pocket\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Model + [App.activeDocument().%s]",pcActiveBody->getNameInDocument(),pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str()); - App::DocumentObjectGroup* grp = sketch->getGroup(); - if (grp) { - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),sketch->getNameInDocument()); - } - updateActive(); - if (isActiveObjectValid()) { - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); - } - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - - copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument()); -} - -bool CmdPartDesignPocket::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Revolution -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignRevolution); - -CmdPartDesignRevolution::CmdPartDesignRevolution() - : Command("PartDesign_Revolution") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Revolution"); - sToolTipText = QT_TR_NOOP("Revolve a selected sketch"); - sWhatsThis = "PartDesign_Revolution"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Revolution"; -} - -void CmdPartDesignRevolution::activated(int iMsg) -{ - PartDesign::Body *pcActiveBody = getBody(); - - bool bNoSketchWasSelected = false; - // Get a valid sketch from the user - // First check selections - std::vector sketches = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - if (sketches.size() == 0) {//no sketches were selected. Let user pick an object from valid ones available in document - sketches = getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); - bNoSketchWasSelected = true; - } - Gui::validateSketches(sketches, false); - if (sketches.size() == 0) { - if (bNoSketchWasSelected) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), - QObject::tr("Please create a sketch or 2D object first.")); - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches selected"), - QObject::tr("None of selected sketches/2D objects is valid for revolving. Please select a valid sketch or 2D object that is not used by any other feature.")); - } - return; - } - - // If there is more than one selection/possibility, show dialog and let user pick sketch - if (sketches.size() > 1) { - PartDesignGui::FeaturePickDialog Dlg(sketches); - if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) - return; // Cancelled or nothing selected - } - - Part::Part2DObject* sketch = static_cast(sketches.front()); - App::DocumentObject* support = sketch->Support.getValue(); - std::string FeatName = getUniqueObjectName("Revolution"); - - openCommand("Make Revolution"); - doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Revolution\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s.Model + [App.activeDocument().%s]",pcActiveBody->getNameInDocument(),pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",pcActiveBody->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", - FeatName.c_str(), sketch->getNameInDocument()); - doCommand(Doc,"App.activeDocument().%s.Angle = 360.0",FeatName.c_str()); - PartDesign::Revolution* pcRevolution = static_cast(getDocument()->getObject(FeatName.c_str())); - if (pcRevolution && pcRevolution->suggestReversed()) - doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str()); - App::DocumentObjectGroup* grp = sketch->getGroup(); - if (grp) { - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),sketch->getNameInDocument()); - } - updateActive(); - if (isActiveObjectValid()) { - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); - if (support) - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); - } - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - - if (support) { - copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument()); - copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument()); - } -} - -bool CmdPartDesignRevolution::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Groove -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignGroove); - -CmdPartDesignGroove::CmdPartDesignGroove() - : Command("PartDesign_Groove") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Groove"); - sToolTipText = QT_TR_NOOP("Groove a selected sketch"); - sWhatsThis = "PartDesign_Groove"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Groove"; -} - -void CmdPartDesignGroove::activated(int iMsg) -{ -// // Get a valid sketch from the user -// // First check selections -// std::vector sketches = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); -// Gui::validateSketches(sketches, true); -// // Next let the user choose from a list of all eligible objects -// if (sketches.size() == 0) { -// sketches = getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); -// Gui::validateSketches(sketches, true); -// if (sketches.size() == 0) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), -// QObject::tr("Please create a sketch or 2D object first. It must have a support face on a solid.")); -// return; -// } -// } -// // If there is more than one selection/possibility, show dialog and let user pick sketch -// if (sketches.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(sketches); -// if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } -// -// Part::Part2DObject* sketch = static_cast(sketches.front()); -// App::DocumentObject* support = sketch->Support.getValue(); -// std::string FeatName = getUniqueObjectName("Groove"); -// -// openCommand("Make Groove"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Groove\",\"%s\")",FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument()); -// doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", -// FeatName.c_str(), sketch->getNameInDocument()); -// doCommand(Doc,"App.activeDocument().%s.Angle = 360.0",FeatName.c_str()); -// PartDesign::Groove* pcGroove = static_cast(getDocument()->getObject(FeatName.c_str())); -// if (pcGroove && pcGroove->suggestReversed()) -// doCommand(Doc,"App.activeDocument().%s.Reversed = 1",FeatName.c_str()); -// App::DocumentObjectGroup* grp = sketch->getGroup(); -// if (grp) { -// doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),sketch->getNameInDocument()); -// } -// updateActive(); -// if (isActiveObjectValid()) { -// doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument()); -// if (support) -// doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument()); -// } -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// -// if (support) { -// copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument()); -// copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument()); -// copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument()); -// } -} - -bool CmdPartDesignGroove::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Fillet -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignFillet); - -CmdPartDesignFillet::CmdPartDesignFillet() - :Command("PartDesign_Fillet") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Fillet"); - sToolTipText = QT_TR_NOOP("Make a fillet on an edge, face or body"); - sWhatsThis = "PartDesign_Fillet"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Fillet"; -} - -void CmdPartDesignFillet::activated(int iMsg) -{ - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select an edge, face or body. Only one body is allowed.")); - return; - } - - if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), - QObject::tr("Fillet works only on parts.")); - return; - } - std::string SelString = selection[0].getAsPropertyLinkSubString(); - Part::Feature *base = static_cast(selection[0].getObject()); -// -// const Part::TopoShape& TopShape = base->Shape.getShape(); -// if (TopShape._Shape.IsNull()){ -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Shape of selected part is empty.")); -// return; -// } -// -// TopTools_IndexedMapOfShape mapOfEdges; -// TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; -// TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); -// TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges); -// -// std::vector SubNames = std::vector(selection[0].getSubNames()); -// -// unsigned int i = 0; -// -// while(i < SubNames.size()) -// { -// std::string aSubName = static_cast(SubNames.at(i)); -// -// if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") { -// TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str())); -// const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge); -// -// if(los.Extent() != 2) -// { -// SubNames.erase(SubNames.begin()+i); -// continue; -// } -// -// const TopoDS_Shape& face1 = los.First(); -// const TopoDS_Shape& face2 = los.Last(); -// GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge), -// TopoDS::Face(face1), -// TopoDS::Face(face2)); -// if (cont != GeomAbs_C0) { -// SubNames.erase(SubNames.begin()+i); -// continue; -// } -// -// i++; -// } -// else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") { -// TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str())); -// -// TopTools_IndexedMapOfShape mapOfFaces; -// TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces); -// -// for(int j = 1; j <= mapOfFaces.Extent(); ++j) { -// TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j)); -// -// int id = mapOfEdges.FindIndex(edge); -// -// std::stringstream buf; -// buf << "Edge"; -// buf << id; -// -// if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end()) -// { -// SubNames.push_back(buf.str()); -// } -// -// } -// -// SubNames.erase(SubNames.begin()+i); -// } -// // empty name or any other sub-element -// else { -// SubNames.erase(SubNames.begin()+i); -// } -// } -// -// if (SubNames.size() == 0) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No fillet possible on selected faces/edges.")); -// return; -// } -// -// std::string SelString; -// SelString += "(App."; -// SelString += "ActiveDocument";//getObject()->getDocument()->getName(); -// SelString += "."; -// SelString += selection[0].getFeatName(); -// SelString += ",["; -// for(std::vector::const_iterator it = SubNames.begin();it!=SubNames.end();++it){ -// SelString += "\""; -// SelString += *it; -// SelString += "\""; -// if(it != --SubNames.end()) -// SelString += ","; -// } -// SelString += "])"; -// - std::string FeatName = getUniqueObjectName("Fillet"); - - openCommand("Make Fillet"); - doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Fillet\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); - doCommand(Gui,"Gui.Selection.clearSelection()"); - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - App::DocumentObjectGroup* grp = base->getGroup(); - if (grp) { - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - } - - copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName()); - copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName()); - copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName()); -} - -bool CmdPartDesignFillet::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Chamfer -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignChamfer); - -CmdPartDesignChamfer::CmdPartDesignChamfer() - :Command("PartDesign_Chamfer") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Chamfer"); - sToolTipText = QT_TR_NOOP("Chamfer the selected edges of a shape"); - sWhatsThis = "PartDesign_Chamfer"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Chamfer"; -} - -void CmdPartDesignChamfer::activated(int iMsg) -{ - std::vector selection = getSelection().getSelectionEx(); - - if (selection.size() != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select an edge, face or body. Only one body is allowed.")); - return; - } - - if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), - QObject::tr("Chamfer works only on parts.")); - return; - } - std::string SelString = selection[0].getAsPropertyLinkSubString(); - - Part::Feature *base = static_cast(selection[0].getObject()); -// -// const Part::TopoShape& TopShape = base->Shape.getShape(); -// -// if (TopShape._Shape.IsNull()){ -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Shape of selected part is empty.")); -// return; -// } -// -// TopTools_IndexedMapOfShape mapOfEdges; -// TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; -// TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); -// TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges); -// -// std::vector SubNames = std::vector(selection[0].getSubNames()); -// -// unsigned int i = 0; -// -// while(i < SubNames.size()) -// { -// std::string aSubName = static_cast(SubNames.at(i)); -// -// if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") { -// TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str())); -// const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge); -// -// if(los.Extent() != 2) -// { -// SubNames.erase(SubNames.begin()+i); -// continue; -// } -// -// const TopoDS_Shape& face1 = los.First(); -// const TopoDS_Shape& face2 = los.Last(); -// GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge), -// TopoDS::Face(face1), -// TopoDS::Face(face2)); -// if (cont != GeomAbs_C0) { -// SubNames.erase(SubNames.begin()+i); -// continue; -// } -// -// i++; -// } -// else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") { -// TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str())); -// -// TopTools_IndexedMapOfShape mapOfFaces; -// TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces); -// -// for(int j = 1; j <= mapOfFaces.Extent(); ++j) { -// TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j)); -// -// int id = mapOfEdges.FindIndex(edge); -// -// std::stringstream buf; -// buf << "Edge"; -// buf << id; -// -// if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end()) -// { -// SubNames.push_back(buf.str()); -// } -// -// } -// -// SubNames.erase(SubNames.begin()+i); -// } -// // empty name or any other sub-element -// else { -// SubNames.erase(SubNames.begin()+i); -// } -// } -// -// if (SubNames.size() == 0) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), -// QObject::tr("No chamfer possible on selected faces/edges.")); -// return; -// } -// -// std::string SelString; -// SelString += "(App."; -// SelString += "ActiveDocument";//getObject()->getDocument()->getName(); -// SelString += "."; -// SelString += selection[0].getFeatName(); -// SelString += ",["; -// for(std::vector::const_iterator it = SubNames.begin();it!=SubNames.end();++it){ -// SelString += "\""; -// SelString += *it; -// SelString += "\""; -// if(it != --SubNames.end()) -// SelString += ","; -// } -// SelString += "])"; -// - std::string FeatName = getUniqueObjectName("Chamfer"); - - openCommand("Make Chamfer"); - doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Chamfer\",\"%s\")",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); - doCommand(Gui,"Gui.Selection.clearSelection()"); - doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); - doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); - App::DocumentObjectGroup* grp = base->getGroup(); - if (grp) { - doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - } - - copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName()); - copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName()); - copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName()); -} - -bool CmdPartDesignChamfer::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Draft -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignDraft); - -CmdPartDesignDraft::CmdPartDesignDraft() - :Command("PartDesign_Draft") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Draft"); - sToolTipText = QT_TR_NOOP("Make a draft on a face"); - sWhatsThis = "PartDesign_Draft"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Draft"; -} - -void CmdPartDesignDraft::activated(int iMsg) -{ -// std::vector selection = getSelection().getSelectionEx(); -// -// if (selection.size() < 1) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), -// QObject::tr("Select one or more faces.")); -// return; -// } -// -// if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), -// QObject::tr("Draft works only on parts.")); -// return; -// } -// -// Part::Feature *base = static_cast(selection[0].getObject()); -// -// const Part::TopoShape& TopShape = base->Shape.getShape(); -// if (TopShape._Shape.IsNull()){ -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), -// QObject::tr("Shape of selected Part is empty.")); -// return; -// } -// -// std::vector SubNames = std::vector(selection[0].getSubNames()); -// unsigned int i = 0; -// -// while(i < SubNames.size()) -// { -// std::string aSubName = static_cast(SubNames.at(i)); -// -// if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") { -// // Check for valid face types -// TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str())); -// BRepAdaptor_Surface sf(face); -// if ((sf.GetType() != GeomAbs_Plane) && (sf.GetType() != GeomAbs_Cylinder) && (sf.GetType() != GeomAbs_Cone)) -// SubNames.erase(SubNames.begin()+i); -// } else { -// // empty name or any other sub-element -// SubNames.erase(SubNames.begin()+i); -// } -// -// i++; -// } -// -// if (SubNames.size() == 0) { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), -// QObject::tr("No draft possible on selected faces.")); -// return; -// } -// -// std::string SelString; -// SelString += "(App."; -// SelString += "ActiveDocument"; -// SelString += "."; -// SelString += selection[0].getFeatName(); -// SelString += ",["; -// for(std::vector::const_iterator it = SubNames.begin();it!=SubNames.end();++it){ -// SelString += "\""; -// SelString += *it; -// SelString += "\""; -// if(it != --SubNames.end()) -// SelString += ","; -// } -// SelString += "])"; -// -// std::string FeatName = getUniqueObjectName("Draft"); -// -// // We don't create any defaults for neutral plane and pull direction, but Draft::execute() -// // will choose them. -// // Note: When the body feature is there, the best thing would be to get pull direction and -// // neutral plane from the preceding feature in the tree. Or even store them as default in -// // the Body feature itself -// openCommand("Make Draft"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Draft\",\"%s\")",FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); -// doCommand(Doc,"App.activeDocument().%s.Angle = %f",FeatName.c_str(), 1.5); -// updateActive(); -// if (isActiveObjectValid()) { -// doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); -// } -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// App::DocumentObjectGroup* grp = base->getGroup(); -// if (grp) { -// doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),FeatName.c_str()); -// } -// -// copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName()); -// copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName()); -// copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName()); -} - -bool CmdPartDesignDraft::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Mirrored -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignMirrored); - -CmdPartDesignMirrored::CmdPartDesignMirrored() - : Command("PartDesign_Mirrored") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Mirrored"); - sToolTipText = QT_TR_NOOP("Create a mirrored feature"); - sWhatsThis = "PartDesign_Mirrored"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Mirrored"; -} - -void CmdPartDesignMirrored::activated(int iMsg) -{ -// // Get a valid original from the user -// // First check selections -// std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // Next create a list of all eligible objects -// if (features.size() == 0) { -// features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // If there is more than one selected or eligible object, show dialog and let user pick one -// if (features.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(features); -// if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } else { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), -// QObject::tr("Please create a subtractive or additive feature first.")); -// return; -// } -// } -// -// std::string FeatName = getUniqueObjectName("Mirrored"); -// -// std::stringstream str; -// std::vector tempSelNames; -// str << "App.activeDocument()." << FeatName << ".Originals = ["; -// for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ -// str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; -// tempSelNames.push_back((*it)->getNameInDocument()); -// } -// str << "]"; -// -// openCommand("Mirrored"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",FeatName.c_str()); -// // FIXME: There seems to be kind of a race condition here, leading to sporadic errors like -// // 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()); -// 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()); -// -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// -// copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); -// copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); -} - -bool CmdPartDesignMirrored::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_LinearPattern -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignLinearPattern); - -CmdPartDesignLinearPattern::CmdPartDesignLinearPattern() - : Command("PartDesign_LinearPattern") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("LinearPattern"); - sToolTipText = QT_TR_NOOP("Create a linear pattern feature"); - sWhatsThis = "PartDesign_LinearPattern"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_LinearPattern"; -} - -void CmdPartDesignLinearPattern::activated(int iMsg) -{ -// // Get a valid original from the user -// // First check selections -// std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // Next create a list of all eligible objects -// if (features.size() == 0) { -// features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // If there is more than one selected or eligible object, show dialog and let user pick one -// if (features.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(features); -// if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } else { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), -// QObject::tr("Please create a subtractive or additive feature first, please.")); -// return; -// } -// } -// -// std::string FeatName = getUniqueObjectName("LinearPattern"); -// -// std::stringstream str; -// std::vector tempSelNames; -// str << "App.activeDocument()." << FeatName << ".Originals = ["; -// for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ -// str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; -// tempSelNames.push_back((*it)->getNameInDocument()); -// } -// str << "]"; -// -// openCommand("LinearPattern"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",FeatName.c_str()); -// updateActive(); -// doCommand(Doc,str.str().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) -// doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); -// -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// App::DocumentObjectGroup* grp = sketch->getGroup(); -// if (grp) { -// doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),sketch->getNameInDocument()); -// } -// -// copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); -// copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); -} - -bool CmdPartDesignLinearPattern::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_PolarPattern -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignPolarPattern); - -CmdPartDesignPolarPattern::CmdPartDesignPolarPattern() - : Command("PartDesign_PolarPattern") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("PolarPattern"); - sToolTipText = QT_TR_NOOP("Create a polar pattern feature"); - sWhatsThis = "PartDesign_PolarPattern"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_PolarPattern"; -} - -void CmdPartDesignPolarPattern::activated(int iMsg) -{ -// // Get a valid original from the user -// // First check selections -// std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // Next create a list of all eligible objects -// if (features.size() == 0) { -// features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // If there is more than one selected or eligible object, show dialog and let user pick one -// if (features.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(features); -// if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } else { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), -// QObject::tr("Please create a subtractive or additive feature first, please.")); -// return; -// } -// } -// -// std::string FeatName = getUniqueObjectName("PolarPattern"); -// -// std::stringstream str; -// std::vector tempSelNames; -// str << "App.activeDocument()." << FeatName << ".Originals = ["; -// for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ -// str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; -// tempSelNames.push_back((*it)->getNameInDocument()); -// } -// str << "]"; -// -// openCommand("PolarPattern"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",FeatName.c_str()); -// updateActive(); -// doCommand(Doc,str.str().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) -// doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); -// -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// App::DocumentObjectGroup* grp = sketch->getGroup(); -// if (grp) { -// doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" -// ,grp->getNameInDocument(),sketch->getNameInDocument()); -// } -// -// copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); -// copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); -} - -bool CmdPartDesignPolarPattern::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_Scaled -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignScaled); - -CmdPartDesignScaled::CmdPartDesignScaled() - : Command("PartDesign_Scaled") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("Scaled"); - sToolTipText = QT_TR_NOOP("Create a scaled feature"); - sWhatsThis = "PartDesign_Scaled"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_Scaled"; -} - -void CmdPartDesignScaled::activated(int iMsg) -{ -// // Get a valid original from the user -// // First check selections -// std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // Next create a list of all eligible objects -// if (features.size() == 0) { -// features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // If there is more than one selected or eligible object, show dialog and let user pick one -// if (features.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(features); -// if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } else { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), -// QObject::tr("Please create a subtractive or additive feature first, please.")); -// return; -// } -// } -// -// std::string FeatName = getUniqueObjectName("Scaled"); -// -// std::stringstream str; -// std::vector tempSelNames; -// str << "App.activeDocument()." << FeatName << ".Originals = ["; -// for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ -// str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; -// tempSelNames.push_back((*it)->getNameInDocument()); -// } -// str << "]"; -// -// openCommand("Scaled"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Scaled\",\"%s\")",FeatName.c_str()); -// updateActive(); -// doCommand(Doc,str.str().c_str()); -// doCommand(Doc,"App.activeDocument().%s.Factor = 2", FeatName.c_str()); -// doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str()); -// for (std::vector::iterator it = tempSelNames.begin(); it != tempSelNames.end(); ++it) -// doCommand(Gui,"Gui.activeDocument().%s.Visibility=False",it->c_str()); -// -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// -// copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); -// copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); -} - -bool CmdPartDesignScaled::isActive(void) -{ - return hasActiveDocument(); -} - -//=========================================================================== -// PartDesign_MultiTransform -//=========================================================================== -DEF_STD_CMD_A(CmdPartDesignMultiTransform); - -CmdPartDesignMultiTransform::CmdPartDesignMultiTransform() - : Command("PartDesign_MultiTransform") -{ - sAppModule = "PartDesign"; - sGroup = QT_TR_NOOP("PartDesign"); - sMenuText = QT_TR_NOOP("MultiTransform"); - sToolTipText = QT_TR_NOOP("Create a multitransform feature"); - sWhatsThis = "PartDesign_MultiTransform"; - sStatusTip = sToolTipText; - sPixmap = "PartDesign_MultiTransform"; -} - -void CmdPartDesignMultiTransform::activated(int iMsg) -{ -// // Get a valid original from the user -// // First check selections -// std::vector features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// std::vector subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // Next create a list of all eligible objects -// if (features.size() == 0) { -// features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId()); -// subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId()); -// features.insert(features.end(), subtractive.begin(), subtractive.end()); -// // If there is more than one selected or eligible object, show dialog and let user pick one -// if (features.size() > 1) { -// PartDesignGui::FeaturePickDialog Dlg(features); -// if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty()) -// return; // Cancelled or nothing selected -// } else { -// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), -// QObject::tr("Please create a subtractive or additive feature first, please.")); -// return; -// } -// } -// -// std::string FeatName = getUniqueObjectName("MultiTransform"); -// -// std::stringstream str; -// std::vector tempSelNames; -// str << "App.activeDocument()." << FeatName << ".Originals = ["; -// for (std::vector::iterator it = features.begin(); it != features.end(); ++it){ -// str << "App.activeDocument()." << (*it)->getNameInDocument() << ","; -// tempSelNames.push_back((*it)->getNameInDocument()); -// } -// str << "]"; -// -// openCommand("MultiTransform"); -// doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::MultiTransform\",\"%s\")",FeatName.c_str()); -// updateActive(); -// doCommand(Doc,str.str().c_str()); -// -// doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); -// -// copyVisual(FeatName.c_str(), "ShapeColor", tempSelNames.front().c_str()); -// copyVisual(FeatName.c_str(), "DisplayMode", tempSelNames.front().c_str()); -} - -bool CmdPartDesignMultiTransform::isActive(void) -{ - return hasActiveDocument(); -} - - -//=========================================================================== -// Initialization -//=========================================================================== - -void CreatePartDesignCommands(void) -{ - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - - rcCmdMgr.addCommand(new CmdPartDesignPad()); - rcCmdMgr.addCommand(new CmdPartDesignPocket()); - rcCmdMgr.addCommand(new CmdPartDesignRevolution()); -// rcCmdMgr.addCommand(new CmdPartDesignGroove()); - rcCmdMgr.addCommand(new CmdPartDesignFillet()); -// rcCmdMgr.addCommand(new CmdPartDesignDraft()); - rcCmdMgr.addCommand(new CmdPartDesignNewSketch()); - rcCmdMgr.addCommand(new CmdPartDesignChamfer()); -// rcCmdMgr.addCommand(new CmdPartDesignMirrored()); -// rcCmdMgr.addCommand(new CmdPartDesignLinearPattern()); -// rcCmdMgr.addCommand(new CmdPartDesignPolarPattern()); -// //rcCmdMgr.addCommand(new CmdPartDesignScaled()); -// rcCmdMgr.addCommand(new CmdPartDesignMultiTransform()); - } -======= /*************************************************************************** * Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de) * * * @@ -1522,7 +81,6 @@ PartDesign::Body *getBody(void) } - //=========================================================================== // PartDesign_Sketch //=========================================================================== @@ -1658,37 +216,46 @@ bool CmdPartDesignNewSketch::isActive(void) //=========================================================================== // Take a list of Part2DObjects and erase those which are not eligible for creating a -// SketchBased feature. If supportRequired is true, also erase those that cannot be used to define -// a Subtractive feature -void validateSketches(std::vector& sketches, const bool supportRequired) -{ - std::vector::iterator s = sketches.begin(); +// SketchBased feature. + const unsigned validateSketches(std::vector& sketches, + std::vector& status, + std::vector::iterator& firstValidSketch) +{ + // TODO: If the user previously opted to allow multiple use of sketches or use of sketches from other bodies, + // then count these as valid sketches! + unsigned validSketches = 0; + firstValidSketch = sketches.end(); - while (s != sketches.end()) { - // sketch is always part of the body first. - //// Check whether this sketch is already being used by another feature - //std::vector ref = (*s)->getInList(); - //std::vector::iterator r = ref.begin(); - //while (r != ref.end()) { - // if (!(*r)->getTypeId().isDerivedFrom(PartDesign::SketchBased().getClassTypeId())) { - // r = ref.erase(r); - // continue; - // } - // ++r; - //} - //if (!ref.empty()) { - // // TODO: Display some information message that this sketch was removed? - // s = sketches.erase(s); - // continue; - //} + for (std::vector::iterator s = sketches.begin(); s != sketches.end(); s++) { + // Check whether this sketch is already being used by another feature + // Body features don't count... + std::vector inList = (*s)->getInList(); + std::vector::iterator o = inList.begin(); + while (o != inList.end()) { + Base::Console().Error("InList: %s\n", (*o)->getNameInDocument()); + if ((*o)->getTypeId().isDerivedFrom(PartDesign::Body::getClassTypeId())) + o = inList.erase(o); + else + ++o; + } + if (inList.size() > 0) { + status.push_back(PartDesignGui::FeaturePickDialog::isUsed); + continue; + } + + // Check whether this sketch belongs to the active body + PartDesign::Body* body = getBody(); + if (!body->hasFeature(*s)) { + status.push_back(PartDesignGui::FeaturePickDialog::otherBody); + continue; + } // Check whether the sketch shape is valid Part::Part2DObject* sketch = static_cast(*s); const TopoDS_Shape& shape = sketch->Shape.getValue(); if (shape.IsNull()) { - s = sketches.erase(s); + status.push_back(PartDesignGui::FeaturePickDialog::invalidShape); continue; - // TODO: Display some information message that this sketch was removed? } // count free wires @@ -1698,24 +265,18 @@ void validateSketches(std::vector& sketches, const bool su ctWires++; } if (ctWires == 0) { - s = sketches.erase(s); + status.push_back(PartDesignGui::FeaturePickDialog::noWire); continue; - // TODO: Display some information message that this sketch was removed? } - // Check for support - if (supportRequired) { - App::DocumentObject* support = sketch->Support.getValue(); - if (support == NULL) { - s = sketches.erase(s); - continue; - // TODO: Display some information message that this sketch was removed? - } - } - - // All checks passed - go on to next candidate - s++; + // All checks passed - found a valid sketch + if (firstValidSketch == sketches.end()) + firstValidSketch = s; + validSketches++; + status.push_back(PartDesignGui::FeaturePickDialog::validFeature); } + + return validSketches; } void prepareSketchBased(Gui::Command* cmd, const std::string& which, @@ -1724,35 +285,40 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, PartDesign::Body *pcActiveBody = getBody(); if (!pcActiveBody) return; - bool bNoSketchWasSelected = false; // Get a valid sketch from the user // First check selections + FeatName = ""; // Empty string means prepareSketchBased() was not successful + std::vector status; + std::vector::iterator firstValidSketch; std::vector sketches = cmd->getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - validateSketches(sketches, false); - // Next let the user choose from a list of all eligible objects - if (sketches.size() == 0) { + // Next let the user choose from a list of all eligible objects + unsigned validSketches = validateSketches(sketches, status, firstValidSketch); + if (validSketches == 0) { + status.clear(); sketches = cmd->getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); - bNoSketchWasSelected = true; - } - if (sketches.size() == 0) { - if (bNoSketchWasSelected) { + validSketches = validateSketches(sketches, status, firstValidSketch); + if (validSketches == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches in this document"), - QObject::tr("Please create a sketch or 2D object first")); +<<<<<<< 135164d3d8f15df2a58ef70fc1fae48b59c89679 + QObject::tr("Please create a sketch or 2D object first.")); } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid sketches selected"), QObject::tr("None of selected sketches/2D objects is valid for padding. Please select a valid sketch or 2D object that is not used by any other feature.")); +======= + QObject::tr("Please create a sketch or 2D object first")); + return; +>>>>>>> Enhanced Pick dialog for PartDesign feature's sketches } - return; } - // If there is more than one selection/possibility, show dialog and let user pick sketch - if (sketches.size() > 1) { - PartDesignGui::FeaturePickDialog Dlg(sketches); + if (validSketches > 1) { + PartDesignGui::FeaturePickDialog Dlg(sketches, status); if ((Dlg.exec() != QDialog::Accepted) || (sketches = Dlg.getFeatures()).empty()) return; // Cancelled or nothing selected + firstValidSketch = sketches.begin(); } - sketch = static_cast(sketches.front()); + sketch = static_cast(*firstValidSketch); FeatName = cmd->getUniqueObjectName(which.c_str()); cmd->openCommand((std::string("Make ") + which).c_str()); @@ -1764,7 +330,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch, const std::string& FeatName) { - App::DocumentObjectGroup* grp = sketch->getGroup(); + App::DocumentObjectGroup* grp = sketch->getGroup(); if (grp) { cmd->doCommand(cmd->Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" ,grp->getNameInDocument(),FeatName.c_str()); @@ -1775,18 +341,17 @@ void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch cmd->updateActive(); if (cmd->isActiveObjectValid()) { cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument()); - } + } // #0001721: use '0' as edit value to avoid switching off selection in // ViewProviderGeometryObject::setEditViewer - cmd->doCommand(cmd->Gui,"Gui.activeDocument().setEdit('%s', 0)", FeatName.c_str()); + cmd->doCommand(cmd->Gui,"Gui.activeDocument().setEdit('%s', 0)", FeatName.c_str()); - /* PartDesign::Body *pcActiveBody = getBody(); if (pcActiveBody) { cmd->copyVisual(FeatName.c_str(), "ShapeColor", pcActiveBody->getNameInDocument()); cmd->copyVisual(FeatName.c_str(), "LineColor", pcActiveBody->getNameInDocument()); cmd->copyVisual(FeatName.c_str(), "PointColor", pcActiveBody->getNameInDocument()); - }*/ + } } //=========================================================================== @@ -1811,6 +376,7 @@ void CmdPartDesignPad::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Pad", sketch, FeatName); + if (FeatName.empty()) return; // specific parameters for Pad doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); @@ -1835,7 +401,7 @@ CmdPartDesignPocket::CmdPartDesignPocket() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("Pocket"); - sToolTipText = QT_TR_NOOP("create a pocket with the selected sketch"); + sToolTipText = QT_TR_NOOP("Create a pocket with the selected sketch"); sWhatsThis = "PartDesign_Pocket"; sStatusTip = sToolTipText; sPixmap = "PartDesign_Pocket"; @@ -1846,6 +412,7 @@ void CmdPartDesignPocket::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Pocket", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str()); @@ -1880,6 +447,7 @@ void CmdPartDesignRevolution::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Revolution", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", FeatName.c_str(), sketch->getNameInDocument()); @@ -1919,6 +487,7 @@ void CmdPartDesignGroove::activated(int iMsg) Part::Part2DObject* sketch; std::string FeatName; prepareSketchBased(this, "Groove", sketch, FeatName); + if (FeatName.empty()) return; doCommand(Doc,"App.activeDocument().%s.ReferenceAxis = (App.activeDocument().%s,['V_Axis'])", FeatName.c_str(), sketch->getNameInDocument()); @@ -1965,7 +534,7 @@ void CmdPartDesignFillet::activated(int iMsg) if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), - QObject::tr("Fillet works only on parts")); + QObject::tr("Fillet works only on parts.")); return; } @@ -1974,7 +543,7 @@ void CmdPartDesignFillet::activated(int iMsg) const Part::TopoShape& TopShape = base->Shape.getShape(); if (TopShape._Shape.IsNull()){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Shape of selected part is empty")); + QObject::tr("Shape of selected part is empty.")); return; } @@ -2045,7 +614,7 @@ void CmdPartDesignFillet::activated(int iMsg) if (SubNames.size() == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No fillet possible on selected faces/edges")); + QObject::tr("No fillet possible on selected faces/edges.")); return; } @@ -2069,6 +638,7 @@ void CmdPartDesignFillet::activated(int iMsg) openCommand("Make Fillet"); doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Fillet\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); + doCommand(Gui,"Gui.Selection.clearSelection()"); doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); App::DocumentObjectGroup* grp = base->getGroup(); @@ -2116,7 +686,7 @@ void CmdPartDesignChamfer::activated(int iMsg) if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), - QObject::tr("Chamfer works only on parts")); + QObject::tr("Chamfer works only on parts.")); return; } @@ -2126,7 +696,7 @@ void CmdPartDesignChamfer::activated(int iMsg) if (TopShape._Shape.IsNull()){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Shape of selected part is empty")); + QObject::tr("Shape of selected part is empty.")); return; } @@ -2197,7 +767,7 @@ void CmdPartDesignChamfer::activated(int iMsg) if (SubNames.size() == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No chamfer possible on selected faces/edges")); + QObject::tr("No chamfer possible on selected faces/edges.")); return; } @@ -2221,6 +791,7 @@ void CmdPartDesignChamfer::activated(int iMsg) openCommand("Make Chamfer"); doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Chamfer\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str()); + doCommand(Gui,"Gui.Selection.clearSelection()"); doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName()); doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); App::DocumentObjectGroup* grp = base->getGroup(); @@ -2268,7 +839,7 @@ void CmdPartDesignDraft::activated(int iMsg) if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"), - QObject::tr("Draft works only on parts")); + QObject::tr("Draft works only on parts.")); return; } @@ -2277,7 +848,7 @@ void CmdPartDesignDraft::activated(int iMsg) const Part::TopoShape& TopShape = base->Shape.getShape(); if (TopShape._Shape.IsNull()){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Shape of selected Part is empty")); + QObject::tr("Shape of selected Part is empty.")); return; } @@ -2304,7 +875,7 @@ void CmdPartDesignDraft::activated(int iMsg) if (SubNames.size() == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No draft possible on selected faces")); + QObject::tr("No draft possible on selected faces.")); return; } @@ -2366,7 +937,7 @@ CmdPartDesignMirrored::CmdPartDesignMirrored() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("Mirrored"); - sToolTipText = QT_TR_NOOP("create a mirrored feature"); + sToolTipText = QT_TR_NOOP("Create a mirrored feature"); sWhatsThis = "PartDesign_Mirrored"; sStatusTip = sToolTipText; sPixmap = "PartDesign_Mirrored"; @@ -2391,7 +962,7 @@ void CmdPartDesignMirrored::activated(int iMsg) return; // Cancelled or nothing selected } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), - QObject::tr("Please create a subtractive or additive feature first")); + QObject::tr("Please create a subtractive or additive feature first.")); return; } } @@ -2442,7 +1013,7 @@ CmdPartDesignLinearPattern::CmdPartDesignLinearPattern() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("LinearPattern"); - sToolTipText = QT_TR_NOOP("create a linear pattern feature"); + sToolTipText = QT_TR_NOOP("Create a linear pattern feature"); sWhatsThis = "PartDesign_LinearPattern"; sStatusTip = sToolTipText; sPixmap = "PartDesign_LinearPattern"; @@ -2467,7 +1038,7 @@ void CmdPartDesignLinearPattern::activated(int iMsg) return; // Cancelled or nothing selected } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), - QObject::tr("Please create a subtractive or additive feature first, please")); + QObject::tr("Please create a subtractive or additive feature first, please.")); return; } } @@ -2525,7 +1096,7 @@ CmdPartDesignPolarPattern::CmdPartDesignPolarPattern() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("PolarPattern"); - sToolTipText = QT_TR_NOOP("create a polar pattern feature"); + sToolTipText = QT_TR_NOOP("Create a polar pattern feature"); sWhatsThis = "PartDesign_PolarPattern"; sStatusTip = sToolTipText; sPixmap = "PartDesign_PolarPattern"; @@ -2550,7 +1121,7 @@ void CmdPartDesignPolarPattern::activated(int iMsg) return; // Cancelled or nothing selected } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), - QObject::tr("Please create a subtractive or additive feature first, please")); + QObject::tr("Please create a subtractive or additive feature first, please.")); return; } } @@ -2608,7 +1179,7 @@ CmdPartDesignScaled::CmdPartDesignScaled() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("Scaled"); - sToolTipText = QT_TR_NOOP("create a scaled feature"); + sToolTipText = QT_TR_NOOP("Create a scaled feature"); sWhatsThis = "PartDesign_Scaled"; sStatusTip = sToolTipText; sPixmap = "PartDesign_Scaled"; @@ -2633,7 +1204,7 @@ void CmdPartDesignScaled::activated(int iMsg) return; // Cancelled or nothing selected } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), - QObject::tr("Please create a subtractive or additive feature first, please")); + QObject::tr("Please create a subtractive or additive feature first, please.")); return; } } @@ -2680,7 +1251,7 @@ CmdPartDesignMultiTransform::CmdPartDesignMultiTransform() sAppModule = "PartDesign"; sGroup = QT_TR_NOOP("PartDesign"); sMenuText = QT_TR_NOOP("MultiTransform"); - sToolTipText = QT_TR_NOOP("create a multitransform feature"); + sToolTipText = QT_TR_NOOP("Create a multitransform feature"); sWhatsThis = "PartDesign_MultiTransform"; sStatusTip = sToolTipText; sPixmap = "PartDesign_MultiTransform"; @@ -2705,7 +1276,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg) return; // Cancelled or nothing selected } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"), - QObject::tr("Please create a subtractive or additive feature first, please")); + QObject::tr("Please create a subtractive or additive feature first, please.")); return; } } @@ -2760,4 +1331,3 @@ void CreatePartDesignCommands(void) //rcCmdMgr.addCommand(new CmdPartDesignScaled()); rcCmdMgr.addCommand(new CmdPartDesignMultiTransform()); } ->>>>>>> Integrated PartDesign::Pad into Body feature workflow diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp index 029e4e76b..c46b6662d 100644 --- a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp @@ -39,12 +39,51 @@ using namespace PartDesignGui; -FeaturePickDialog::FeaturePickDialog(std::vector& objects) +const QString FeaturePickDialog::getFeatureStatusString(const featureStatus st) +{ + switch (st) { + case validFeature: return tr("Valid"); + case invalidShape: return tr("Invalid shape"); + case noWire: return tr("No wire in sketch"); + case isUsed: return tr("Sketch already used by other feature"); + case otherBody: return tr("Sketch belongs to another Body feature"); + } + + return tr(""); +} + +FeaturePickDialog::FeaturePickDialog(std::vector& objects, + const std::vector& status) : QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog) { ui->setupUi(this); - for (std::vector::const_iterator o = objects.begin(); o != objects.end(); ++o) - ui->listWidget->addItem(QString::fromLatin1((*o)->getNameInDocument())); + + connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherBody(bool))); + connect(ui->checkOtherFeature, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherFeature(bool))); + connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + + ui->checkOtherBody->setChecked(false); + ui->checkOtherBody->setEnabled(false); // TODO: implement + ui->checkOtherFeature->setChecked(false); + ui->checkOtherFeature->setEnabled(false); // TODO: implement + ui->radioIndependent->setChecked(true); + ui->radioIndependent->setEnabled(false); + // These are not implemented yet + ui->radioDependent->setEnabled(false); + ui->radioXRef->setEnabled(false); + + std::vector::const_iterator st = status.begin(); + for (std::vector::const_iterator o = objects.begin(); o != objects.end(); ++o) { + QListWidgetItem* item = new QListWidgetItem(QString::fromAscii((*o)->getNameInDocument()) + + QString::fromAscii(" (") + getFeatureStatusString(*st) + QString::fromAscii(")")); + ui->listWidget->addItem(item); + st++; + } + + statuses = status; + updateList(); } FeaturePickDialog::~FeaturePickDialog() @@ -52,6 +91,50 @@ FeaturePickDialog::~FeaturePickDialog() } +void FeaturePickDialog::updateList() +{ + int index = 0; + + for (std::vector::const_iterator st = statuses.begin(); st != statuses.end(); st++) { + QListWidgetItem* item = ui->listWidget->item(index); + + switch (*st) { + case validFeature: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break; + case invalidShape: item->setFlags(Qt::NoItemFlags); break; + case noWire: item->setFlags(Qt::NoItemFlags); break; + case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break; + case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break; + } + + index++; + } +} + +void FeaturePickDialog::onCheckOtherFeature(bool checked) +{ + ui->radioIndependent->setEnabled(checked); + // TODO: Not implemented yet + //ui->radioDependent->setEnabled(checked); + //ui->radioXRef->setEnabled(checked); + + updateList(); +} + +void FeaturePickDialog::onCheckOtherBody(bool checked) +{ + ui->radioIndependent->setEnabled(checked); + // TODO: Not implemented yet + //ui->radioDependent->setEnabled(checked); + //ui->radioXRef->setEnabled(checked); + + updateList(); +} + +void FeaturePickDialog::onUpdate(bool) +{ + updateList(); +} + std::vector FeaturePickDialog::getFeatures() { std::vector result; @@ -67,8 +150,11 @@ void FeaturePickDialog::accept() { features.clear(); QListIterator i(ui->listWidget->selectedItems()); - while (i.hasNext()) - features.push_back(i.next()->text()); + while (i.hasNext()) { + QString t = i.next()->text(); + t = t.left(t.indexOf(QString::fromAscii("(")) - 1); + features.push_back(t); + } QDialog::accept(); } diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp.orig b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp.orig new file mode 100644 index 000000000..598d7bb96 --- /dev/null +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.cpp.orig @@ -0,0 +1,166 @@ +/****************************************************************************** + * Copyright (c)2012 Jan Rheinlaender * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ******************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include "ui_FeaturePickDialog.h" +#include "FeaturePickDialog.h" + +using namespace PartDesignGui; + +const QString FeaturePickDialog::getFeatureStatusString(const featureStatus st) +{ + switch (st) { + case validFeature: return tr("Valid"); + case invalidShape: return tr("Invalid shape"); + case noWire: return tr("No wire in sketch"); + case isUsed: return tr("Sketch already used by other feature"); + case otherBody: return tr("Sketch belongs to another Body feature"); + } + + return tr(""); +} + +FeaturePickDialog::FeaturePickDialog(std::vector& objects, + const std::vector& status) + : QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog) +{ + ui->setupUi(this); +<<<<<<< 90079612b9f3db27654ac1d04ee2262d99842e1b + for (std::vector::const_iterator o = objects.begin(); o != objects.end(); ++o) + ui->listWidget->addItem(QString::fromLatin1((*o)->getNameInDocument())); +======= + + connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherBody(bool))); + connect(ui->checkOtherFeature, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherFeature(bool))); + connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool))); + + ui->checkOtherBody->setChecked(false); + ui->checkOtherBody->setEnabled(false); // TODO: implement + ui->checkOtherFeature->setChecked(false); + ui->checkOtherFeature->setEnabled(false); // TODO: implement + ui->radioIndependent->setChecked(true); + ui->radioIndependent->setEnabled(false); + // These are not implemented yet + ui->radioDependent->setEnabled(false); + ui->radioXRef->setEnabled(false); + + std::vector::const_iterator st = status.begin(); + for (std::vector::const_iterator o = objects.begin(); o != objects.end(); ++o) { + QListWidgetItem* item = new QListWidgetItem(QString::fromAscii((*o)->getNameInDocument()) + + QString::fromAscii(" (") + getFeatureStatusString(*st) + QString::fromAscii(")")); + ui->listWidget->addItem(item); + st++; + } + + statuses = status; + updateList(); +>>>>>>> Enhanced Pick dialog for PartDesign feature's sketches +} + +FeaturePickDialog::~FeaturePickDialog() +{ + +} + +void FeaturePickDialog::updateList() +{ + int index = 0; + + for (std::vector::const_iterator st = statuses.begin(); st != statuses.end(); st++) { + QListWidgetItem* item = ui->listWidget->item(index); + + switch (*st) { + case validFeature: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break; + case invalidShape: item->setFlags(Qt::NoItemFlags); break; + case noWire: item->setFlags(Qt::NoItemFlags); break; + case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break; + case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break; + } + + index++; + } +} + +void FeaturePickDialog::onCheckOtherFeature(bool checked) +{ + ui->radioIndependent->setEnabled(checked); + // TODO: Not implemented yet + //ui->radioDependent->setEnabled(checked); + //ui->radioXRef->setEnabled(checked); + + updateList(); +} + +void FeaturePickDialog::onCheckOtherBody(bool checked) +{ + ui->radioIndependent->setEnabled(checked); + // TODO: Not implemented yet + //ui->radioDependent->setEnabled(checked); + //ui->radioXRef->setEnabled(checked); + + updateList(); +} + +void FeaturePickDialog::onUpdate(bool) +{ + updateList(); +} + +std::vector FeaturePickDialog::getFeatures() { + std::vector result; + + for (std::vector::const_iterator s = features.begin(); s != features.end(); ++s) + result.push_back(App::GetApplication().getActiveDocument()->getObject(s->toLatin1().data())); + + return result; +} + + + +void FeaturePickDialog::accept() +{ + features.clear(); + QListIterator i(ui->listWidget->selectedItems()); + while (i.hasNext()) { + QString t = i.next()->text(); + t = t.left(t.indexOf(QString::fromAscii("(")) - 1); + features.push_back(t); + } + + QDialog::accept(); +} +#include "moc_FeaturePickDialog.cpp" diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.h b/src/Mod/PartDesign/Gui/FeaturePickDialog.h index c8569d2a2..72a96458e 100644 --- a/src/Mod/PartDesign/Gui/FeaturePickDialog.h +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.h @@ -35,7 +35,15 @@ class FeaturePickDialog : public QDialog Q_OBJECT public: - FeaturePickDialog(std::vector &objects); + enum featureStatus { + validFeature = 0, + invalidShape, + noWire, + isUsed, + otherBody + }; + + FeaturePickDialog(std::vector &objects, const std::vector &status); ~FeaturePickDialog(); std::vector getFeatures(); @@ -43,11 +51,19 @@ public: void accept(); protected Q_SLOTS: + void onCheckOtherFeature(bool); + void onCheckOtherBody(bool); + void onUpdate(bool); private: Ui_FeaturePickDialog* ui; std::vector features; + std::vector statuses; + + void updateList(); + + const QString getFeatureStatusString(const featureStatus st); }; } diff --git a/src/Mod/PartDesign/Gui/FeaturePickDialog.ui b/src/Mod/PartDesign/Gui/FeaturePickDialog.ui index 22e119385..76e5e728a 100644 --- a/src/Mod/PartDesign/Gui/FeaturePickDialog.ui +++ b/src/Mod/PartDesign/Gui/FeaturePickDialog.ui @@ -6,8 +6,8 @@ 0 0 - 218 - 235 + 318 + 357 @@ -17,6 +17,41 @@ + + + + Allow sketch from other Body + + + + + + + Allow sketch used by other feature + + + + + + + Make independent copy (recommended) + + + + + + + Make dependent copy + + + + + + + Create cross-reference + + + diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp index 56d962655..39641b39a 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp @@ -549,10 +549,8 @@ bool TaskDlgPadParameters::reject() // get the support and Sketch PartDesign::Pad* pcPad = static_cast(PadView->getObject()); Sketcher::SketchObject *pcSketch = 0; - App::DocumentObject *pcSupport = 0; if (pcPad->Sketch.getValue()) { - pcSketch = static_cast(pcPad->Sketch.getValue()); - pcSupport = pcSketch->Support.getValue(); + pcSketch = static_cast(pcPad->Sketch.getValue()); } // roll back the done things @@ -563,13 +561,8 @@ bool TaskDlgPadParameters::reject() if (!Gui::Application::Instance->getViewProvider(pcPad)) { if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) Gui::Application::Instance->getViewProvider(pcSketch)->show(); - if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) - Gui::Application::Instance->getViewProvider(pcSupport)->show(); } - //Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - //Gui::Command::commitCommand(); - return true; }