Created Draft feature for PartDesign

This commit is contained in:
jrheinlaender 2012-11-25 20:15:01 +04:30 committed by wmayer
parent ea1ae29985
commit 0773311d5b
16 changed files with 1722 additions and 376 deletions

View File

@ -38,6 +38,7 @@
#include "Body.h"
#include "FeatureDressUp.h"
#include "FeatureChamfer.h"
#include "FeatureDraft.h"
#include "FeatureFace.h"
#include "FeatureSubtractive.h"
#include "FeatureAdditive.h"
@ -96,6 +97,7 @@ void PartDesignExport initPartDesign()
PartDesign::Groove ::init();
PartDesign::Chamfer ::init();
PartDesign::Face ::init();
PartDesign::Draft ::init();
}
} // extern "C"

View File

@ -51,6 +51,8 @@ SET(FeaturesDressUp_SRCS
FeatureFillet.h
FeatureChamfer.cpp
FeatureChamfer.h
FeatureDraft.cpp
FeatureDraft.h
)
SOURCE_GROUP("DressUpFeatures" FILES ${FeaturesDressUp_SRCS})

View File

@ -0,0 +1,283 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
* *
* 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 <BRepOffsetAPI_DraftAngle.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx>
# include <gp_Ax1.hxx>
//# include <BRepAdaptor_CompCurve.hxx>
# include <gp_Pln.hxx>
# include <gp_Lin.hxx>
# include <gp_Dir.hxx>
# include <gp_Circ.hxx>
# include <GeomAbs_SurfaceType.hxx>
# include <GeomAPI_IntSS.hxx>
# include <Geom_Plane.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Line.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
#endif
#include <Mod/Part/App/TopoShape.h>
#include "FeatureDraft.h"
using namespace PartDesign;
#include <Base/Console.h>
PROPERTY_SOURCE(PartDesign::Draft, PartDesign::DressUp)
const App::PropertyFloatConstraint::Constraints floatAngle = {0.0f,89.99f,0.1f};
Draft::Draft()
{
ADD_PROPERTY(Angle,(1.5f));
Angle.setConstraints(&floatAngle);
ADD_PROPERTY_TYPE(NeutralPlane,(0),"Draft",(App::PropertyType)(App::Prop_None),"NeutralPlane");
ADD_PROPERTY_TYPE(PullDirection,(0),"Draft",(App::PropertyType)(App::Prop_None),"PullDirection");
ADD_PROPERTY(Reversed,(0));
}
short Draft::mustExecute() const
{
if (Placement.isTouched() ||
Angle.isTouched() ||
NeutralPlane.isTouched() ||
PullDirection.isTouched() ||
Reversed.isTouched())
return 1;
return DressUp::mustExecute();
}
App::DocumentObjectExecReturn *Draft::execute(void)
{
// Get parameters
// Base shape
App::DocumentObject* link = Base.getValue();
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot draft invalid shape");
// Faces where draft should be applied
const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Face");
if (SubVals.size() == 0)
return new App::DocumentObjectExecReturn("No faces specified");
// Draft angle
float angle = Angle.getValue();
if ((angle < 0.0) || (angle >= 90.0))
return new App::DocumentObjectExecReturn("Draft angle must be between 0 and 90 degrees");
angle = angle / 180.0 * M_PI;
// Pull direction
gp_Dir pullDirection;
App::DocumentObject* refDirection = PullDirection.getValue();
if (refDirection != NULL) {
if (!refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Pull direction reference must be an edge of a feature");
std::vector<std::string> subStrings = PullDirection.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No pull direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refDirection);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract pull direction reference edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Pull direction reference edge must be linear");
pullDirection = adapt.Line().Direction();
} else {
throw Base::Exception("Pull direction reference must be an edge");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
pullDirection.Transform(invObjLoc.Transformation());
}
// Neutral plane
gp_Pln neutralPlane;
App::DocumentObject* refPlane = NeutralPlane.getValue();
if (refPlane == NULL) {
// Try to guess a neutral plane from the first selected face
// Get edges of first selected face
TopoDS_Shape face = TopShape.getSubShape(SubVals[0].c_str());
TopTools_IndexedMapOfShape mapOfEdges;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfEdges);
bool found;
for (int i = 1; i <= mapOfEdges.Extent(); i++) {
// Note: What happens if mapOfEdges(i) is the degenerated edge of a cone?
// But in that case the draft is not possible anyway!
BRepAdaptor_Curve c(TopoDS::Edge(mapOfEdges(i)));
gp_Pnt p1 = c.Value(c.FirstParameter());
gp_Pnt p2 = c.Value(c.LastParameter());
if (c.IsClosed()) {
// Edge is a circle or a circular arc (other types are not allowed for drafting)
neutralPlane = gp_Pln(p1, c.Circle().Axis().Direction());
found = true;
break;
} else {
// Edge is linear
// Find midpoint of edge and create auxiliary plane through midpoint normal to edge
gp_Pnt pm = c.Value((c.FirstParameter() + c.LastParameter()) / 2.0);
Geom_Plane aux(pm, gp_Dir(p2.X() - p1.X(), p2.Y() - p1.Y(), p2.Z() - p1.Z()));
// Intersect plane with face. Is there no easier way?
BRepAdaptor_Surface adapt(TopoDS::Face(face), Standard_False);
Handle_Geom_Surface sf = adapt.Surface().Surface();
//Handle_Geom_Surface auxsf(&aux);
GeomAPI_IntSS intersector(&aux, sf, Precision::Confusion());
if (!intersector.IsDone())
continue;
Handle_Geom_Curve icurve = intersector.Line(1);
if (!icurve->IsKind(STANDARD_TYPE(Geom_Line)))
continue;
// TODO: How to extract the line from icurve without creating an edge first?
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(icurve);
BRepAdaptor_Curve c(edge);
neutralPlane = gp_Pln(pm, c.Line().Direction());
found = true;
break;
}
}
if (!found)
throw Base::Exception("No neutral plane specified and none can be guessed");
} else {
if (!refPlane->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Neutral plane reference must be face of a feature");
std::vector<std::string> subStrings = NeutralPlane.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No neutral plane reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refPlane);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract neutral plane reference face");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Neutral plane reference face must be planar");
neutralPlane = adapt.Plane();
} else if (ref.ShapeType() == TopAbs_EDGE) {
if (refDirection != NULL) {
// Create neutral plane through edge normal to pull direction
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract neutral plane reference edge");
BRepAdaptor_Curve c(refEdge);
if (!c.GetType() == GeomAbs_Line)
throw Base::Exception("Neutral plane reference edge must be linear");
double a = c.Line().Angle(gp_Lin(c.Value(c.FirstParameter()), pullDirection));
if (std::fabs(a - M_PI_2) > Precision::Confusion())
throw Base::Exception("Neutral plane reference edge must be normal to pull direction");
neutralPlane = gp_Pln(c.Value(c.FirstParameter()), pullDirection);
} else {
throw Base::Exception("Neutral plane reference can only be an edge if pull direction is defined");
}
} else {
throw Base::Exception("Neutral plane reference must be a face");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
neutralPlane.Transform(invObjLoc.Transformation());
}
if (refDirection == NULL) {
// Choose pull direction normal to neutral plane
pullDirection = neutralPlane.Axis().Direction();
}
// Reversed pull direction
bool reversed = Reversed.getValue();
if (reversed)
angle *= -1.0;
this->positionByBase();
// create an untransformed copy of the base shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());
try {
BRepOffsetAPI_DraftAngle mkDraft(baseShape._Shape);
// Note:
// LocOpe_SplitDrafts can split a face with a wire and apply draft to both parts
// Not clear though whether the face must have free boundaries
// LocOpe_DPrism can create a stand-alone draft prism. The sketch can only have a single
// wire, though.
// BRepFeat_MakeDPrism requires a support for the operation but will probably support multiple
// wires in the sketch
for (std::vector<std::string>::const_iterator it=SubVals.begin(); it != SubVals.end(); ++it) {
TopoDS_Face face = TopoDS::Face(baseShape.getSubShape(it->c_str()));
// TODO: What is the flag for?
mkDraft.Add(face, pullDirection, angle, neutralPlane);
if (!mkDraft.AddDone()) {
// Note: the function ProblematicShape returns the face on which the error occurred,
mkDraft.Remove(face);
Base::Console().Error("Adding face failed: %u\n", mkDraft.Status());
}
}
mkDraft.Build();
if (!mkDraft.IsDone())
return new App::DocumentObjectExecReturn("Failed to create draft");
TopoDS_Shape shape = mkDraft.Shape();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}

View File

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef PARTDESIGN_FEATUREDRAFT_H
#define PARTDESIGN_FEATUREDRAFT_H
#include <App/PropertyStandard.h>
#include <App/PropertyLinks.h>
#include "FeatureDressUp.h"
namespace PartDesign
{
class PartDesignExport Draft : public DressUp
{
PROPERTY_HEADER(PartDesign::Draft);
public:
Draft();
App::PropertyFloatConstraint Angle;
App::PropertyLinkSub NeutralPlane;
App::PropertyLinkSub PullDirection;
App::PropertyBool Reversed;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
/// returns the type name of the view provider
const char* getViewProviderName(void) const {
return "PartDesignGui::ViewProviderDraft";
}
//@}
};
} //namespace PartDesign
#endif // PARTDESIGN_FEATUREDRAFT_H

View File

@ -15,6 +15,8 @@ libPartDesign_la_SOURCES=\
FeaturePocket.h \
FeatureChamfer.cpp \
FeatureChamfer.h \
FeatureDraft.cpp \
FeatureDraft.h \
FeatureDressUp.cpp \
FeatureDressUp.h \
FeatureGroove.cpp \

View File

@ -36,6 +36,7 @@
#include "ViewProviderPad.h"
#include "ViewProviderChamfer.h"
#include "ViewProviderFillet.h"
#include "ViewProviderDraft.h"
#include "ViewProviderRevolution.h"
#include "ViewProviderGroove.h"
#include "ViewProviderMirrored.h"
@ -92,6 +93,7 @@ void PartDesignGuiExport initPartDesignGui()
PartDesignGui::ViewProviderGroove ::init();
PartDesignGui::ViewProviderChamfer ::init();
PartDesignGui::ViewProviderFillet ::init();
PartDesignGui::ViewProviderDraft ::init();
PartDesignGui::ViewProviderMirrored ::init();
PartDesignGui::ViewProviderLinearPattern ::init();
PartDesignGui::ViewProviderPolarPattern ::init();

View File

@ -31,6 +31,7 @@ set(PartDesignGui_MOC_HDRS
TaskPocketParameters.h
TaskChamferParameters.h
TaskFilletParameters.h
TaskDraftParameters.h
TaskHoleParameters.h
TaskRevolutionParameters.h
TaskGrooveParameters.h
@ -53,6 +54,7 @@ set(PartDesignGui_UIC_SRCS
TaskPocketParameters.ui
TaskChamferParameters.ui
TaskFilletParameters.ui
TaskDraftParameters.ui
TaskHoleParameters.ui
TaskRevolutionParameters.ui
TaskGrooveParameters.ui
@ -78,6 +80,8 @@ SET(PartDesignGuiViewProvider_SRCS
ViewProviderChamfer.h
ViewProviderFillet.cpp
ViewProviderFillet.h
ViewProviderDraft.cpp
ViewProviderDraft.h
ViewProviderRevolution.cpp
ViewProviderRevolution.h
ViewProviderGroove.cpp
@ -115,6 +119,9 @@ SET(PartDesignGuiTaskDlgs_SRCS
TaskFilletParameters.ui
TaskFilletParameters.cpp
TaskFilletParameters.h
TaskDraftParameters.ui
TaskDraftParameters.cpp
TaskDraftParameters.h
TaskRevolutionParameters.ui
TaskRevolutionParameters.cpp
TaskRevolutionParameters.h

View File

@ -20,40 +20,41 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Tool.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopExp.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <QMessageBox>
#endif
#include <sstream>
#include <algorithm>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Mod/Part/App/Part2DObject.h>
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Tool.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopExp.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <QMessageBox>
#endif
#include <sstream>
#include <algorithm>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Mod/Part/App/Part2DObject.h>
#include <Mod/PartDesign/App/FeatureAdditive.h>
#include <Mod/PartDesign/App/FeatureSubtractive.h>
using namespace std;
#include "FeaturePickDialog.h"
using namespace std;
#include "FeaturePickDialog.h"
namespace Gui {
//===========================================================================
// Common utility functions
@ -62,7 +63,7 @@ namespace Gui {
// 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<App::DocumentObject*>& sketches, const bool supportRequired)
void validateSketches(std::vector<App::DocumentObject*>& sketches, const bool supportRequired)
{
std::vector<App::DocumentObject*>::iterator s = sketches.begin();
@ -448,130 +449,130 @@ CmdPartDesignFillet::CmdPartDesignFillet()
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Fillet";
}
void CmdPartDesignFillet::activated(int iMsg)
{
std::vector<Gui::SelectionObject> 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;
}
Part::Feature *base = static_cast<Part::Feature*>(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<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(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<std::string>::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.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",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());
}
void CmdPartDesignFillet::activated(int iMsg)
{
std::vector<Gui::SelectionObject> 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;
}
Part::Feature *base = static_cast<Part::Feature*>(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<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(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<std::string>::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.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",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)
{
@ -594,137 +595,245 @@ CmdPartDesignChamfer::CmdPartDesignChamfer()
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Chamfer";
}
void CmdPartDesignChamfer::activated(int iMsg)
{
std::vector<Gui::SelectionObject> 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;
}
Part::Feature *base = static_cast<Part::Feature*>(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<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(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<std::string>::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.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",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());
}
void CmdPartDesignChamfer::activated(int iMsg)
{
std::vector<Gui::SelectionObject> 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;
}
Part::Feature *base = static_cast<Part::Feature*>(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<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(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<std::string>::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.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",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 = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Draft";
}
void CmdPartDesignDraft::activated(int iMsg)
{
std::vector<Gui::SelectionObject> 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<Part::Feature*>(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<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(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<std::string>::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.
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());
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
//===========================================================================
@ -744,36 +853,36 @@ CmdPartDesignMirrored::CmdPartDesignMirrored()
void CmdPartDesignMirrored::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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;
}
}
} 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("Mirrored");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@ -818,36 +927,36 @@ CmdPartDesignLinearPattern::CmdPartDesignLinearPattern()
void CmdPartDesignLinearPattern::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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;
}
}
} 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@ -892,36 +1001,36 @@ CmdPartDesignPolarPattern::CmdPartDesignPolarPattern()
void CmdPartDesignPolarPattern::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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;
}
}
} 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@ -966,36 +1075,36 @@ CmdPartDesignScaled::CmdPartDesignScaled()
void CmdPartDesignScaled::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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;
}
}
} 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@ -1039,36 +1148,36 @@ CmdPartDesignMultiTransform::CmdPartDesignMultiTransform()
void CmdPartDesignMultiTransform::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> 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;
}
}
} 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<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@ -1103,6 +1212,7 @@ void CreatePartDesignCommands(void)
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());

View File

@ -8,6 +8,7 @@ BUILT_SOURCES=\
moc_TaskPocketParameters.cpp \
moc_TaskChamferParameters.cpp \
moc_TaskFilletParameters.cpp \
moc_TaskDraftParameters.cpp \
moc_TaskGrooveParameters.cpp \
moc_TaskHoleParameters.cpp \
moc_TaskLinearPatternParameters.cpp \
@ -24,6 +25,7 @@ BUILT_SOURCES=\
ui_TaskPocketParameters.h \
ui_TaskChamferParameters.h \
ui_TaskFilletParameters.h \
ui_TaskDraftParameters.h \
ui_TaskHoleParameters.h \
ui_TaskLinearPatternParameters.h \
ui_TaskMirroredParameters.h \
@ -40,6 +42,7 @@ libPartDesignGui_la_UI=\
TaskPocketParameters.ui \
TaskChamferParameters.ui \
TaskFilletParameters.ui \
TaskFilletParameters.ui \
TaskHoleParameters.ui \
TaskLinearPatternParameters.ui \
TaskMirroredParameters.ui \
@ -68,6 +71,8 @@ libPartDesignGui_la_SOURCES=\
TaskChamferParameters.h \
TaskFilletParameters.cpp \
TaskFilletParameters.h \
TaskDraftParameters.cpp \
TaskDraftParameters.h \
TaskLinearPatternParameters.cpp \
TaskLinearPatternParameters.h \
TaskMirroredParameters.cpp \
@ -106,6 +111,8 @@ libPartDesignGui_la_SOURCES=\
ViewProviderChamfer.h \
ViewProviderFillet.cpp \
ViewProviderFillet.h \
ViewProviderDraft.cpp \
ViewProviderDraft.h \
ViewProviderGroove.cpp \
ViewProviderGroove.h \
ViewProviderRevolution.cpp \

View File

@ -0,0 +1,432 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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_
#endif
#include "ui_TaskDraftParameters.h"
#include "TaskDraftParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureDraft.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskDraftParameters */
TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap("Part_Draft"),tr("Draft parameters"),true, parent),DraftView(DraftView)
{
selectionMode = none;
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskDraftParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->checkReverse, SIGNAL(toggled(bool)),
this, SLOT(onReversedChanged(bool)));
connect(ui->buttonFaceAdd, SIGNAL(toggled(bool)),
this, SLOT(onButtonFaceAdd(bool)));
connect(ui->buttonFaceRemove, SIGNAL(toggled(bool)),
this, SLOT(onButtonFaceRemove(bool)));
connect(ui->buttonPlane, SIGNAL(toggled(bool)),
this, SLOT(onButtonPlane(bool)));
connect(ui->buttonLine, SIGNAL(toggled(bool)),
this, SLOT(onButtonLine(bool)));
this->groupLayout()->addWidget(proxy);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
double a = pcDraft->Angle.getValue();
ui->doubleSpinBox->setMinimum(0.0);
ui->doubleSpinBox->setMaximum(89.99);
ui->doubleSpinBox->setValue(a);
ui->doubleSpinBox->selectAll();
QMetaObject::invokeMethod(ui->doubleSpinBox, "setFocus", Qt::QueuedConnection);
bool r = pcDraft->Reversed.getValue();
ui->checkReverse->setChecked(r);
std::vector<std::string> strings = pcDraft->Base.getSubValues();
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); i++)
{
ui->listWidgetFaces->insertItem(0, QString::fromStdString(*i));
}
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFaces->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFaceDeleted()));
ui->listWidgetFaces->setContextMenuPolicy(Qt::ActionsContextMenu);
strings = pcDraft->NeutralPlane.getSubValues();
std::string neutralPlane = (strings.empty() ? "" : strings[0]);
ui->linePlane->setText(QString::fromStdString(neutralPlane));
strings = pcDraft->PullDirection.getSubValues();
std::string pullDirection = (strings.empty() ? "" : strings[0]);
ui->lineLine->setText(QString::fromStdString(pullDirection));
}
void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (selectionMode == none)
return;
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (strcmp(msg.pDocName, DraftView->getObject()->getDocument()->getName()) != 0)
return;
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
App::DocumentObject* base = this->getBase();
// TODO: Must we make a copy here instead of assigning to const char* ?
const char* fname = base->getNameInDocument();
std::string subName(msg.pSubName);
if ((selectionMode == faceAdd) && (subName.size() > 4 && subName.substr(0,4) == "Face")) {
if (strcmp(msg.pObjectName, fname) != 0)
return;
std::vector<std::string> faces = pcDraft->Base.getSubValues();
if (std::find(faces.begin(), faces.end(), subName) == faces.end()) {
faces.push_back(subName);
pcDraft->Base.setValue(base, faces);
ui->listWidgetFaces->insertItem(0, QString::fromStdString(subName));
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonFaceAdd->setChecked(false);
exitSelectionMode();
}
} else if ((selectionMode == faceRemove) && (subName.size() > 4 && subName.substr(0,4) == "Face")) {
if (strcmp(msg.pObjectName, fname) != 0)
return;
std::vector<std::string> faces = pcDraft->Base.getSubValues();
std::vector<std::string>::iterator f = std::find(faces.begin(), faces.end(), subName);
if (f != faces.end()) {
faces.erase(f);
pcDraft->Base.setValue(base, faces);
QList<QListWidgetItem*> items = ui->listWidgetFaces->findItems(QString::fromStdString(subName), Qt::MatchExactly);
if (!items.empty()) {
for (QList<QListWidgetItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
QListWidgetItem* it = ui->listWidgetFaces->takeItem(ui->listWidgetFaces->row(*i));
delete it;
}
}
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonFaceRemove->setChecked(false);
exitSelectionMode();
}
} else if ((selectionMode == plane) && (subName.size() > 4) &&
((subName.substr(0,4) == "Face") || (subName.substr(0,4) == "Edge"))) {
if (strcmp(msg.pObjectName, fname) != 0)
return;
std::vector<std::string> planes(1,subName);
pcDraft->NeutralPlane.setValue(base, planes);
ui->linePlane->setText(QString::fromStdString(subName));
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonPlane->setChecked(false);
exitSelectionMode();
} else if ((selectionMode == line) && (subName.size() > 4 && subName.substr(0,4) == "Edge")) {
if (strcmp(msg.pObjectName, fname) != 0)
return;
std::vector<std::string> edges(1,subName);
pcDraft->PullDirection.setValue(base, edges);
ui->lineLine->setText(QString::fromStdString(subName));
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonLine->setChecked(false);
exitSelectionMode();
}
}
}
void TaskDraftParameters::onButtonFaceAdd(bool checked)
{
if (checked) {
hideObject();
selectionMode = faceAdd;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
} else {
exitSelectionMode();
}
}
void TaskDraftParameters::onButtonFaceRemove(bool checked)
{
if (checked) {
hideObject();
selectionMode = faceRemove;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
} else {
exitSelectionMode();
}
}
void TaskDraftParameters::onButtonPlane(bool checked)
{
if (checked) {
hideObject();
selectionMode = plane;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true));
} else {
exitSelectionMode();
}
}
void TaskDraftParameters::onButtonLine(bool checked)
{
if (checked) {
hideObject();
selectionMode = line;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true));
} else {
exitSelectionMode();
}
}
const std::vector<std::string> TaskDraftParameters::getFaces(void) const
{
std::vector<std::string> result;
for (int i = 0; i < ui->listWidgetFaces->count(); i++)
result.push_back(ui->listWidgetFaces->item(i)->text().toStdString());
return result;
}
void TaskDraftParameters::onFaceDeleted(void)
{
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
App::DocumentObject* base = pcDraft->Base.getValue();
std::vector<std::string> faces = pcDraft->Base.getSubValues();
faces.erase(faces.begin() + ui->listWidgetFaces->currentRow());
pcDraft->Base.setValue(base, faces);
ui->listWidgetFaces->model()->removeRow(ui->listWidgetFaces->currentRow());
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
const std::string TaskDraftParameters::getPlane(void) const
{
return ui->linePlane->text().toStdString();
}
const std::string TaskDraftParameters::getLine(void) const
{
return ui->lineLine->text().toStdString();
}
void TaskDraftParameters::hideObject()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
App::DocumentObject* base = getBase();
if (doc != NULL && base != NULL) {
doc->setHide(DraftView->getObject()->getNameInDocument());
doc->setShow(base->getNameInDocument());
}
}
void TaskDraftParameters::showObject()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
App::DocumentObject* base = getBase();
if (doc != NULL && base != NULL) {
doc->setShow(DraftView->getObject()->getNameInDocument());
doc->setHide(base->getNameInDocument());
}
}
void TaskDraftParameters::onAngleChanged(double angle)
{
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
pcDraft->Angle.setValue((float)angle);
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
const double TaskDraftParameters::getAngle(void) const
{
return ui->doubleSpinBox->value();
}
void TaskDraftParameters::onReversedChanged(const bool on) {
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
pcDraft->Reversed.setValue(on);
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
const bool TaskDraftParameters::getReversed(void) const
{
return ui->checkReverse->isChecked();
}
App::DocumentObject* TaskDraftParameters::getBase(void) const
{
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
return pcDraft->Base.getValue();
}
TaskDraftParameters::~TaskDraftParameters()
{
delete ui;
}
void TaskDraftParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskDraftParameters::exitSelectionMode()
{
selectionMode = none;
Gui::Selection().rmvSelectionGate();
showObject();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DraftView)
: TaskDialog(),DraftView(DraftView)
{
assert(DraftView);
parameter = new TaskDraftParameters(DraftView);
Content.push_back(parameter);
}
TaskDlgDraftParameters::~TaskDlgDraftParameters()
{
}
//==== calls from the TaskView ===============================================================
void TaskDlgDraftParameters::open()
{
}
void TaskDlgDraftParameters::clicked(int)
{
}
bool TaskDlgDraftParameters::accept()
{
std::string name = DraftView->getObject()->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed());
try {
std::vector<std::string> faces = parameter->getFaces();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument."
<< parameter->getBase()->getNameInDocument() << ",[";
for (std::vector<std::string>::const_iterator it = faces.begin(); it != faces.end(); ++it)
str << "\"" << *it << "\",";
str << "])";
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));
return false;
}
std::string neutralPlane = parameter->getPlane();
if (!neutralPlane.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(parameter->getBase()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(neutralPlane.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str());
std::string pullDirection = parameter->getLine();
if (!pullDirection.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(parameter->getBase()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(pullDirection.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
return true;
}
bool TaskDlgDraftParameters::reject()
{
// get the support
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
App::DocumentObject *pcSupport;
pcSupport = pcDraft->Base.getValue();
// roll back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
// if abort command deleted the object the support is visible again
if (!Gui::Application::Instance->getViewProvider(pcDraft)) {
if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
Gui::Application::Instance->getViewProvider(pcSupport)->show();
}
return true;
}
#include "moc_TaskDraftParameters.cpp"

View File

@ -0,0 +1,126 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskDraftParameters_H
#define GUI_TASKVIEW_TaskDraftParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#include "ViewProviderDraft.h"
class Ui_TaskDraftParameters;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace PartDesignGui {
class TaskDraftParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
{
Q_OBJECT
public:
TaskDraftParameters(ViewProviderDraft *DraftView, QWidget *parent=0);
~TaskDraftParameters();
const double getAngle(void) const;
const bool getReversed(void) const;
const std::vector<std::string> getFaces(void) const;
const std::string getPlane(void) const;
const std::string getLine(void) const;
App::DocumentObject *getBase(void) const;
private Q_SLOTS:
void onAngleChanged(double angle);
void onReversedChanged(bool reversed);
void onButtonFaceAdd(const bool checked);
void onButtonFaceRemove(const bool checked);
void onButtonPlane(const bool checked);
void onButtonLine(const bool checked);
void onFaceDeleted(void);
protected:
void hideObject();
void showObject();
void exitSelectionMode();
protected:
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private:
QWidget* proxy;
Ui_TaskDraftParameters* ui;
ViewProviderDraft *DraftView;
enum selectionModes { none, faceAdd, faceRemove, plane, line };
selectionModes selectionMode;
};
/// simulation dialog for the TaskView
class TaskDlgDraftParameters : public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
TaskDlgDraftParameters(ViewProviderDraft *DraftView);
~TaskDlgDraftParameters();
ViewProviderDraft* getDraftView() const
{ return DraftView; }
public:
/// is called the TaskView when the dialog is opened
virtual void open();
/// is called by the framework if an button is clicked which has no accept or reject role
virtual void clicked(int);
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
/// is called by the framework if the user presses the help button
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
protected:
ViewProviderDraft *DraftView;
TaskDraftParameters *parameter;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::TaskDraftParameters</class>
<widget class="QWidget" name="PartDesignGui::TaskDraftParameters">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>257</width>
<height>285</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="buttonFaceAdd">
<property name="text">
<string>Add face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonFaceRemove">
<property name="text">
<string>Remove face</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidgetFaces"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Draft angle</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>89.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.500000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QToolButton" name="buttonPlane">
<property name="text">
<string>Neutral plane</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="linePlane"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QToolButton" name="buttonLine">
<property name="text">
<string>Pull direction</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineLine"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkReverse">
<property name="text">
<string>Reverse pull direction</string>
</property>
</widget>
</item>
</layout>
<zorder>checkReverse</zorder>
<zorder>listWidgetFaces</zorder>
<zorder>buttonFaceAdd</zorder>
<zorder>buttonFaceRemove</zorder>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,130 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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_
#endif
#include "ViewProviderDraft.h"
#include "TaskDraftParameters.h"
#include <Mod/PartDesign/App/FeatureDraft.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Application.h>
using namespace PartDesignGui;
PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProvider)
ViewProviderDraft::ViewProviderDraft()
{
}
ViewProviderDraft::~ViewProviderDraft()
{
}
void ViewProviderDraft::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act;
act = menu->addAction(QObject::tr("Edit draft"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderDraft::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
// When double-clicking on the item for this fillet the
// object unsets and sets its edit mode without closing
// the task panel
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
TaskDlgDraftParameters *draftDlg = qobject_cast<TaskDlgDraftParameters *>(dlg);
if (draftDlg && draftDlg->getDraftView() != this)
draftDlg = 0; // another pad left open its task panel
if (dlg && !draftDlg) {
QMessageBox msgBox;
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
Gui::Control().closeDialog();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
//if(ModNum == 1)
// Gui::Command::openCommand("Change draft parameters");
// start the edit dialog
if (draftDlg)
Gui::Control().showDialog(draftDlg);
else
Gui::Control().showDialog(new TaskDlgDraftParameters(this));
return true;
}
else {
return PartGui::ViewProviderPart::setEdit(ModNum);
}
}
void ViewProviderDraft::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
// and update the draft
//getSketchObject()->getDocument()->recompute();
// when pressing ESC make sure to close the dialog
Gui::Control().closeDialog();
}
else {
PartGui::ViewProviderPart::unsetEdit(ModNum);
}
}
bool ViewProviderDraft::onDelete(const std::vector<std::string> &)
{
// get the support and Sketch
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(getObject());
App::DocumentObject *pcSupport = 0;
if (pcDraft->Base.getValue()){
pcSupport = static_cast<Sketcher::SketchObject*>(pcDraft->Base.getValue());
}
// if abort command deleted the object the support is visible again
if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport))
Gui::Application::Instance->getViewProvider(pcSupport)->show();
return true;
}

View File

@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef PARTGUI_ViewProviderDraft_H
#define PARTGUI_ViewProviderDraft_H
#include "ViewProvider.h"
namespace PartDesignGui {
class PartDesignGuiExport ViewProviderDraft : public ViewProvider
{
PROPERTY_HEADER(PartDesignGui::ViewProviderDraft);
public:
/// constructor
ViewProviderDraft();
/// destructor
virtual ~ViewProviderDraft();
/// grouping handling
void setupContextMenu(QMenu*, QObject*, const char*);
virtual bool onDelete(const std::vector<std::string> &);
protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
};
} // namespace PartDesignGui
#endif // PARTGUI_ViewProviderDraft_H

View File

@ -86,6 +86,7 @@ void Workbench::activated()
"Sketcher_NewSketch",
"PartDesign_Fillet",
"PartDesign_Chamfer",
"PartDesign_Draft",
0};
Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
"SELECT Part::Feature SUBELEMENT Face COUNT 1",
@ -97,6 +98,7 @@ void Workbench::activated()
const char* Faces[] = {
"PartDesign_Fillet",
"PartDesign_Chamfer",
"PartDesign_Draft",
0};
Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
"SELECT Part::Feature SUBELEMENT Face COUNT 2..",
@ -212,6 +214,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "PartDesign_Groove"
<< "PartDesign_Fillet"
<< "PartDesign_Chamfer"
<< "PartDesign_Draft"
<< "PartDesign_Mirrored"
<< "PartDesign_LinearPattern"
<< "PartDesign_PolarPattern"
@ -243,6 +246,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "PartDesign_Groove"
<< "PartDesign_Fillet"
<< "PartDesign_Chamfer"
<< "PartDesign_Draft"
<< "PartDesign_Mirrored"
<< "PartDesign_LinearPattern"
<< "PartDesign_PolarPattern"