Add thickness function

This commit is contained in:
wmayer 2012-11-26 21:10:09 +01:00
parent 4af7221a70
commit 72bba68c2b
21 changed files with 926 additions and 33 deletions

View File

@ -345,6 +345,14 @@ void Document::abortTransaction()
}
}
bool Document::hasPendingTransaction() const
{
if (d->activeUndoTransaction)
return true;
else
return false;
}
void Document::clearUndos()
{
if (d->activeUndoTransaction)

View File

@ -208,6 +208,8 @@ public:
void commitTransaction();
/// Abort the actually running transaction.
void abortTransaction();
/// Check if a transaction is open
bool hasPendingTransaction() const;
/// Set the Undo limit in Byte!
void setUndoLimit(unsigned int UndoMemSize=0);
/// Returns the actual memory consumption of the Undo redo stuff.

View File

@ -23,6 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
# include <QDir>
# include <QKeySequence>
# include <QMessageBox>
@ -389,6 +390,11 @@ void Command::abortCommand(void)
Gui::Application::Instance->activeDocument()->abortCommand();
}
bool Command::hasPendingCommand(void)
{
return Gui::Application::Instance->activeDocument()->hasPendingCommand();
}
bool Command::_blockCmd = false;
void Command::blockCommand(bool block)
@ -447,6 +453,20 @@ void Command::copyVisual(const char* to, const char* attr_to, const char* from,
doCommand(Gui,"Gui.ActiveDocument.%s.%s=Gui.ActiveDocument.%s.%s", to, attr_to, from, attr_from);
}
std::string Command::getPythonTuple(const std::string& name, const std::vector<std::string>& subnames)
{
std::stringstream str;
std::vector<std::string>::const_iterator last = --subnames.end();
str << "(App.ActiveDocument." << name << ",[";
for (std::vector<std::string>::const_iterator it = subnames.begin();it!=subnames.end();++it){
str << "\"" << *it << "\"";
if (it != last)
str << ",";
}
str << "])";
return str.str();
}
const std::string Command::strToPython(const char* Str)
{
return Base::InterpreterSingleton::strToPython(Str);

View File

@ -209,6 +209,8 @@ public:
static void commitCommand(void);
/// Abort the Undo transaction on the active document
static void abortCommand(void);
/// Check if an Undo transaction is open on the active document
static bool hasPendingCommand(void);
/// Updates the (active) document (propagate changes)
static void updateActive(void);
/// Updates the (all or listed) documents (propagate changes)
@ -237,6 +239,8 @@ public:
static void runCommand(DoCmd_Type eType,const char* sCmd);
static void copyVisual(const char* to, const char* attr, const char* from);
static void copyVisual(const char* to, const char* attr_to, const char* from, const char* attr_from);
/// Get Python tuple from object and sub-elements
static std::string getPythonTuple(const std::string& name, const std::vector<std::string>& subnames);
/// import an external module only once
//static void addModule(const char* sModuleName);
/// translate a string to a python string literal (needed e.g. in file names for windows...)

View File

@ -1090,7 +1090,12 @@ void Document::commitCommand(void)
void Document::abortCommand(void)
{
getDocument()->abortTransaction();
getDocument()->abortTransaction();
}
bool Document::hasPendingCommand(void) const
{
return getDocument()->hasPendingTransaction();
}
/// Get a string vector with the 'Undo' actions

View File

@ -181,6 +181,8 @@ public:
void commitCommand(void);
/// Abort the Undo transaction on the document
void abortCommand(void);
/// Check if an Undo transaction is open
bool hasPendingCommand(void) const;
/// Get an Undo string vector with the Undo names
std::vector<std::string> getUndoVector(void) const;
/// Get an Redo string vector with the Redo names

View File

@ -199,6 +199,7 @@ void PartExport initPart()
Part::Loft ::init();
Part::Sweep ::init();
Part::Offset ::init();
Part::Thickness ::init();
// Geometry types
Part::Geometry ::init();

View File

@ -375,11 +375,6 @@ short Offset::mustExecute() const
return 0;
}
void Offset::onChanged(const App::Property* prop)
{
Part::Feature::onChanged(prop);
}
App::DocumentObjectExecReturn *Offset::execute(void)
{
App::DocumentObject* source = Source.getValue();
@ -399,3 +394,71 @@ App::DocumentObjectExecReturn *Offset::execute(void)
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
// ----------------------------------------------------------------------------
const char* Part::Thickness::ModeEnums[]= {"Skin","Pipe", "RectoVerso",NULL};
const char* Part::Thickness::JoinEnums[]= {"Arc","Tangent", "Intersection",NULL};
PROPERTY_SOURCE(Part::Thickness, Part::Feature)
Thickness::Thickness()
{
ADD_PROPERTY_TYPE(Faces,(0),"Thickness",App::Prop_None,"Source shape");
ADD_PROPERTY_TYPE(Value,(1.0),"Thickness",App::Prop_None,"Thickness value");
ADD_PROPERTY_TYPE(Mode,(long(0)),"Thickness",App::Prop_None,"Mode");
Mode.setEnums(ModeEnums);
ADD_PROPERTY_TYPE(Join,(long(0)),"Thickness",App::Prop_None,"Join type");
Join.setEnums(JoinEnums);
ADD_PROPERTY_TYPE(Intersection,(false),"Thickness",App::Prop_None,"Intersection");
ADD_PROPERTY_TYPE(SelfIntersection,(false),"Thickness",App::Prop_None,"Self Intersection");
}
short Thickness::mustExecute() const
{
if (Faces.isTouched())
return 1;
if (Value.isTouched())
return 1;
if (Mode.isTouched())
return 1;
if (Join.isTouched())
return 1;
if (Intersection.isTouched())
return 1;
if (SelfIntersection.isTouched())
return 1;
return 0;
}
App::DocumentObjectExecReturn *Thickness::execute(void)
{
App::DocumentObject* source = Faces.getValue();
if (!(source && source->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No source shape linked.");
const TopoShape& shape = static_cast<Part::Feature*>(source)->Shape.getShape();
if (shape.isNull())
return new App::DocumentObjectExecReturn("Source shape is empty.");
if (shape._Shape.ShapeType() != TopAbs_SOLID)
return new App::DocumentObjectExecReturn("Source shape is not a solid.");
TopTools_ListOfShape closingFaces;
const std::vector<std::string>& subStrings = Faces.getSubValues();
for (std::vector<std::string>::const_iterator it = subStrings.begin(); it != subStrings.end(); ++it) {
TopoDS_Face face = TopoDS::Face(shape.getSubShape(it->c_str()));
closingFaces.Append(face);
}
double thickness = Value.getValue();
double tol = Precision::Confusion();
bool inter = Intersection.getValue();
bool self = SelfIntersection.getValue();
short mode = (short)Mode.getValue();
short join = (short)Join.getValue();
if (fabs(thickness) > 2*tol)
this->Shape.setValue(shape.makeThickSolid(closingFaces, thickness, tol, inter, self, mode, join));
else
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}

View File

@ -132,8 +132,34 @@ public:
}
//@}
protected:
void onChanged (const App::Property* prop);
private:
static const char* ModeEnums[];
static const char* JoinEnums[];
};
class Thickness : public Part::Feature
{
PROPERTY_HEADER(Part::Thickness);
public:
Thickness();
App::PropertyLinkSub Faces;
App::PropertyFloat Value;
App::PropertyEnumeration Mode;
App::PropertyEnumeration Join;
App::PropertyBool Intersection;
App::PropertyBool SelfIntersection;
/** @name methods override feature */
//@{
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
const char* getViewProviderName(void) const {
return "PartGui::ViewProviderThickness";
}
//@}
private:
static const char* ModeEnums[];

View File

@ -106,6 +106,7 @@ void PartGuiExport initPartGui()
PartGui::ViewProviderLoft ::init();
PartGui::ViewProviderSweep ::init();
PartGui::ViewProviderOffset ::init();
PartGui::ViewProviderThickness ::init();
PartGui::ViewProviderCustom ::init();
PartGui::ViewProviderCustomPython ::init();
PartGui::ViewProviderBoolean ::init();

View File

@ -43,6 +43,7 @@ set(PartGui_MOC_HDRS
TaskLoft.h
TaskOffset.h
TaskSweep.h
TaskThickness.h
TaskCheckGeometry.h
)
fc_wrap_cpp(PartGui_MOC_SRCS ${PartGui_MOC_HDRS})
@ -166,6 +167,8 @@ SET(PartGui_SRCS
TaskSweep.cpp
TaskSweep.h
TaskSweep.ui
TaskThickness.cpp
TaskThickness.h
TaskCheckGeometry.cpp
TaskCheckGeometry.h
)

View File

@ -1035,6 +1035,72 @@ bool CmdPartOffset::isActive(void)
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdPartThickness);
CmdPartThickness::CmdPartThickness()
: Command("Part_Thickness")
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("Thickness...");
sToolTipText = QT_TR_NOOP("Utility to apply a thickness");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "Part_Thickness";
}
void CmdPartThickness::activated(int iMsg)
{
Gui::SelectionFilter faceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1..");
if (!faceFilter.match()) {
QMessageBox::warning(Gui::getMainWindow(),
QApplication::translate("CmdPartThickness", "Wrong selection"),
QApplication::translate("CmdPartThickness", "Selected one or more faces of a shape"));
return;
}
// get the selected object
const std::vector<Gui::SelectionObject>& result = faceFilter.Result[0];
std::string selection = result.front().getAsPropertyLinkSubString();
const Part::Feature* shape = static_cast<const Part::Feature*>(result.front().getObject());
if (shape->Shape.getValue().IsNull())
return;
if (shape->Shape.getValue().ShapeType() != TopAbs_SOLID) {
QMessageBox::warning(Gui::getMainWindow(),
QApplication::translate("CmdPartThickness", "Wrong selection"),
QApplication::translate("CmdPartThickness", "Selected shape is not a solid"));
return;
}
std::string thick = getUniqueObjectName("Thickness");
openCommand("Make Thickness");
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Thickness\",\"%s\")",thick.c_str());
doCommand(Doc,"App.ActiveDocument.%s.Faces = %s" ,thick.c_str(), selection.c_str());
doCommand(Doc,"App.ActiveDocument.%s.Value = 1.0",thick.c_str());
updateActive();
if (isActiveObjectValid())
doCommand(Gui,"Gui.ActiveDocument.hide(\"%s\")",shape->getNameInDocument());
doCommand(Gui,"Gui.ActiveDocument.setEdit('%s')",thick.c_str());
//commitCommand();
adjustCameraPosition();
copyVisual(thick.c_str(), "ShapeColor", shape->getNameInDocument());
copyVisual(thick.c_str(), "LineColor" , shape->getNameInDocument());
copyVisual(thick.c_str(), "PointColor", shape->getNameInDocument());
}
bool CmdPartThickness::isActive(void)
{
Base::Type partid = Base::Type::fromName("Part::Feature");
bool objectsSelected = Gui::Selection().countObjectsOfType(partid) > 0;
return (objectsSelected && !Gui::Control().activeDialog());
}
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdShapeInfo);
CmdShapeInfo::CmdShapeInfo()
@ -1306,5 +1372,6 @@ void CreatePartCommands(void)
rcCmdMgr.addCommand(new CmdPartLoft());
rcCmdMgr.addCommand(new CmdPartSweep());
rcCmdMgr.addCommand(new CmdPartOffset());
rcCmdMgr.addCommand(new CmdPartThickness());
rcCmdMgr.addCommand(new CmdCheckGeometry());
}

View File

@ -27,6 +27,7 @@
<file>icons/Part_ShapeInfo.svg</file>
<file>icons/Part_Sphere.svg</file>
<file>icons/Part_Sweep.svg</file>
<file>icons/Part_Thickness.svg</file>
<file>icons/Part_Torus.svg</file>
<file>icons/preferences-part_design.svg</file>
<file>icons/Tree_Part.svg</file>

View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2682"
sodipodi:version="0.32"
inkscape:version="0.48.0 r9654"
sodipodi:docname="Part_Extrude.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
id="defs2684">
<linearGradient
id="linearGradient3593">
<stop
style="stop-color:#c8e0f9;stop-opacity:1;"
offset="0"
id="stop3595" />
<stop
style="stop-color:#637dca;stop-opacity:1;"
offset="1"
id="stop3597" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3593"
id="radialGradient3354"
gradientUnits="userSpaceOnUse"
cx="330.63791"
cy="39.962704"
fx="330.63791"
fy="39.962704"
r="19.571428"
gradientTransform="matrix(0.9327663,0,0,0.9327663,-298.15651,8.1913381)" />
<linearGradient
id="linearGradient3864">
<stop
id="stop3866"
offset="0"
style="stop-color:#71b2f8;stop-opacity:1;" />
<stop
id="stop3868"
offset="1"
style="stop-color:#002795;stop-opacity:1;" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective2690" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3864"
id="radialGradient2401"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.959337,5.1799939e-2,0,0.7352325,-29.610908,-1.2314128)"
cx="51.105499"
cy="23.807407"
fx="51.105499"
fy="23.807407"
r="19.571428" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3864"
id="radialGradient2404"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.2993671,-1.5757258e-2,8.4161044e-3,0.9850979,-94.354208,-10.998387)"
cx="48.288067"
cy="46.74614"
fx="48.288067"
fy="46.74614"
r="19.571428" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3593"
id="radialGradient3377"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.9327663,0,0,0.9327663,-267.16323,12.515981)"
cx="317.68173"
cy="35.227276"
fx="317.68173"
fy="35.227276"
r="19.571428" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.75"
inkscape:cx="61.342448"
inkscape:cy="37.42735"
inkscape:current-layer="g3381"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="758"
inkscape:window-x="0"
inkscape:window-y="19"
inkscape:window-maximized="0" />
<metadata
id="metadata2687">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<g
id="g3381">
<path
sodipodi:nodetypes="cccccc"
id="path3379"
d="M 36.363637,60.272727 L 59.454546,53.545455 L 62.363637,51.363636 L 62.363637,43.181818 L 54.909091,42.090909 L 36.363637,60.272727 z"
style="opacity:0.63944205;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="opacity:1;fill:url(#radialGradient3354);fill-opacity:1;fill-rule:evenodd;stroke:#4b4dba;stroke-width:2.2;stroke-linecap:butt;stroke-linejoin:bevel;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 4.9501369,37.23429 L 36.070613,40.053788 L 35.816223,59.36629 L 5.1197308,56.292401 L 4.9501369,37.23429 z"
id="rect2568"
sodipodi:nodetypes="ccccc" />
<path
style="opacity:1;fill:url(#radialGradient3377);fill-opacity:1;fill-rule:evenodd;stroke:#4b4dba;stroke-width:2.20000000000000018;stroke-linecap:butt;stroke-linejoin:bevel;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 35.773823,40.117385 L 55.107525,31.319703 L 54.768337,49.869032 L 35.604229,59.429887 L 35.773823,40.117385 z"
id="path3375"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
id="rect3633"
d="M 23.530174,28.496274 L 55.6968,30.8755 L 36.406189,40.084227 L 4.2395647,37.705001 L 23.530174,28.496274 z"
style="fill:url(#radialGradient2404);fill-opacity:1;fill-rule:evenodd;stroke:#000137;stroke-width:2.2;stroke-linecap:butt;stroke-linejoin:bevel;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -67,6 +67,8 @@ public:
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
: d(new Private())
{
if (!Gui::Command::hasPendingCommand())
Gui::Command::openCommand("Edit offset");
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part");
@ -75,6 +77,7 @@ OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
d->ui.spinOffset->setValue(d->offset->Value.getValue());
d->ui.spinOffset->setRange(-INT_MAX, INT_MAX);
d->ui.spinOffset->setSingleStep(0.1);
d->ui.facesButton->hide();
}
OffsetWidget::~OffsetWidget()
@ -177,6 +180,7 @@ bool OffsetWidget::reject()
// roll back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
Gui::Command::updateActive();
return true;
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>256</width>
<height>260</height>
<width>264</width>
<height>244</height>
</rect>
</property>
<property name="windowTitle">
@ -21,7 +21,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="spinOffset"/>
</item>
<item row="1" column="0">
@ -31,7 +31,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="2">
<widget class="QComboBox" name="modeType">
<item>
<property name="text">
@ -57,7 +57,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="2">
<widget class="QComboBox" name="joinType">
<item>
<property name="text">
@ -83,30 +83,13 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="selfIntersection">
<property name="text">
<string>Self-intersection</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="updateView">
<property name="text">
<string>Update view</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="fillOffset">
<property name="text">
@ -114,6 +97,50 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QLabel" name="labelFaces">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QPushButton" name="facesButton">
<property name="text">
<string>Faces</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>152</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="0" colspan="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="updateView">
<property name="text">
<string>Update view</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>

View File

@ -0,0 +1,313 @@
/***************************************************************************
* Copyright (c) 2012 Werner Mayer <wmayer[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 <QEventLoop>
# include <QMessageBox>
# include <QTextStream>
#endif
#include "ui_TaskOffset.h"
#include "TaskThickness.h"
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
#include <Gui/ViewProvider.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Mod/Part/App/PartFeatures.h>
using namespace PartGui;
class ThicknessWidget::Private
{
public:
Ui_TaskOffset ui;
QEventLoop loop;
QString text;
std::string selection;
Part::Thickness* thickness;
bool edit;
Private() : edit(false)
{
}
~Private()
{
}
class FaceSelection : public Gui::SelectionFilterGate
{
const App::DocumentObject* object;
public:
FaceSelection(const App::DocumentObject* obj)
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0), object(obj)
{
}
bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName)
{
if (pObj != this->object)
return false;
if (!sSubName || sSubName[0] == '\0')
return false;
std::string element(sSubName);
return element.substr(0,4) == "Face";
}
};
};
/* TRANSLATOR PartGui::ThicknessWidget */
ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent)
: d(new Private())
{
if (!Gui::Command::hasPendingCommand()) {
d->edit = true;
Gui::Command::openCommand("Edit thickness");
}
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part");
d->thickness = thickness;
d->ui.setupUi(this);
d->ui.spinOffset->setValue(d->thickness->Value.getValue());
d->ui.spinOffset->setRange(-INT_MAX, INT_MAX);
d->ui.spinOffset->setSingleStep(0.1);
d->ui.labelOffset->setText(tr("Thickness"));
d->ui.fillOffset->hide();
}
ThicknessWidget::~ThicknessWidget()
{
delete d;
}
Part::Thickness* ThicknessWidget::getObject() const
{
return d->thickness;
}
void ThicknessWidget::on_spinOffset_valueChanged(double val)
{
d->thickness->Value.setValue((float)val);
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
void ThicknessWidget::on_modeType_activated(int val)
{
d->thickness->Mode.setValue(val);
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
void ThicknessWidget::on_joinType_activated(int val)
{
d->thickness->Join.setValue((float)val);
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
void ThicknessWidget::on_intersection_toggled(bool on)
{
d->thickness->Intersection.setValue(on);
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
void ThicknessWidget::on_selfIntersection_toggled(bool on)
{
d->thickness->SelfIntersection.setValue(on);
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
void ThicknessWidget::on_facesButton_clicked()
{
if (!d->loop.isRunning()) {
QList<QWidget*> c = this->findChildren<QWidget*>();
for (QList<QWidget*>::iterator it = c.begin(); it != c.end(); ++it)
(*it)->setEnabled(false);
d->ui.facesButton->setEnabled(true);
d->ui.labelFaces->setText(tr("Select faces of the source object and press 'Done'"));
d->ui.labelFaces->setEnabled(true);
d->text = d->ui.facesButton->text();
d->ui.facesButton->setText(tr("Done"));
Gui::Application::Instance->showViewProvider(d->thickness->Faces.getValue());
Gui::Application::Instance->hideViewProvider(d->thickness);
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new Private::FaceSelection(d->thickness->Faces.getValue()));
d->loop.exec();
}
else {
QList<QWidget*> c = this->findChildren<QWidget*>();
for (QList<QWidget*>::iterator it = c.begin(); it != c.end(); ++it)
(*it)->setEnabled(true);
d->ui.facesButton->setText(d->text);
d->ui.labelFaces->clear();
d->loop.quit();
d->selection = Gui::Command::getPythonTuple
(d->thickness->Faces.getValue()->getNameInDocument(), d->thickness->Faces.getSubValues());
std::vector<Gui::SelectionObject> sel = Gui::Selection().getSelectionEx();
for (std::vector<Gui::SelectionObject>::iterator it = sel.begin(); it != sel.end(); ++it) {
if (it->getObject() == d->thickness->Faces.getValue()) {
d->thickness->Faces.setValue(it->getObject(), it->getSubNames());
d->selection = it->getAsPropertyLinkSubString();
break;
}
}
Gui::Selection().rmvSelectionGate();
Gui::Application::Instance->showViewProvider(d->thickness);
Gui::Application::Instance->hideViewProvider(d->thickness->Faces.getValue());
if (d->ui.updateView->isChecked())
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
}
void ThicknessWidget::on_updateView_toggled(bool on)
{
if (on) {
d->thickness->getDocument()->recomputeFeature(d->thickness);
}
}
bool ThicknessWidget::accept()
{
if (d->loop.isRunning())
return false;
std::string name = d->thickness->getNameInDocument();
try {
if (!d->selection.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Faces = %s",
name.c_str(),d->selection.c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Value = %f",
name.c_str(),d->ui.spinOffset->value());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Mode = %i",
name.c_str(),d->ui.modeType->currentIndex());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Join = %i",
name.c_str(),d->ui.joinType->currentIndex());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Intersection = %s",
name.c_str(),d->ui.intersection->isChecked() ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.SelfIntersection = %s",
name.c_str(),d->ui.selfIntersection->isChecked() ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!d->thickness->isValid())
throw Base::Exception(d->thickness->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(this, tr("Input error"), QString::fromAscii(e.what()));
return false;
}
return true;
}
bool ThicknessWidget::reject()
{
if (d->loop.isRunning())
return false;
// object has been created right before opening this panel
if (d->edit == false) {
App::DocumentObject* source = d->thickness->Faces.getValue();
if (source){
Gui::Application::Instance->getViewProvider(source)->show();
}
}
// roll back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
Gui::Command::updateActive();
return true;
}
void ThicknessWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
d->ui.retranslateUi(this);
d->ui.labelOffset->setText(tr("Thickness"));
}
}
/* TRANSLATOR PartGui::TaskThickness */
TaskThickness::TaskThickness(Part::Thickness* offset)
{
widget = new ThicknessWidget(offset);
widget->setWindowTitle(ThicknessWidget::tr("Thickness"));
taskbox = new Gui::TaskView::TaskBox(
Gui::BitmapFactory().pixmap("Part_Thickness"),
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
}
TaskThickness::~TaskThickness()
{
}
Part::Thickness* TaskThickness::getObject() const
{
return widget->getObject();
}
void TaskThickness::open()
{
}
void TaskThickness::clicked(int)
{
}
bool TaskThickness::accept()
{
return widget->accept();
}
bool TaskThickness::reject()
{
return widget->reject();
}
#include "moc_TaskThickness.cpp"

View File

@ -0,0 +1,87 @@
/***************************************************************************
* Copyright (c) 2012 Werner Mayer <wmayer[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 PARTGUI_TASKTHICKNESS_H
#define PARTGUI_TASKTHICKNESS_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
namespace Part { class Thickness; }
namespace PartGui {
class ThicknessWidget : public QWidget
{
Q_OBJECT
public:
ThicknessWidget(Part::Thickness*, QWidget* parent = 0);
~ThicknessWidget();
bool accept();
bool reject();
Part::Thickness* getObject() const;
private Q_SLOTS:
void on_spinOffset_valueChanged(double);
void on_modeType_activated(int);
void on_joinType_activated(int);
void on_intersection_toggled(bool);
void on_selfIntersection_toggled(bool);
void on_facesButton_clicked();
void on_updateView_toggled(bool);
private:
void changeEvent(QEvent *e);
private:
class Private;
Private* d;
};
class TaskThickness : public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
TaskThickness(Part::Thickness*);
~TaskThickness();
public:
void open();
bool accept();
bool reject();
void clicked(int);
Part::Thickness* getObject() const;
QDialogButtonBox::StandardButtons getStandardButtons() const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
private:
ThicknessWidget* widget;
Gui::TaskView::TaskBox* taskbox;
};
} //namespace PartGui
#endif // PARTGUI_TASKTHICKNESS_H

View File

@ -47,6 +47,7 @@
#include "ViewProviderMirror.h"
#include "DlgFilletEdges.h"
#include "TaskOffset.h"
#include "TaskThickness.h"
using namespace PartGui;
@ -477,3 +478,84 @@ bool ViewProviderOffset::onDelete(const std::vector<std::string> &)
return true;
}
// ---------------------------------------
PROPERTY_SOURCE(PartGui::ViewProviderThickness, PartGui::ViewProviderPart)
ViewProviderThickness::ViewProviderThickness()
{
sPixmap = "Part_Thickness";
}
ViewProviderThickness::~ViewProviderThickness()
{
}
void ViewProviderThickness::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act;
act = menu->addAction(QObject::tr("Edit thickness"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderThickness::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
TaskThickness* thicknessDlg = qobject_cast<TaskThickness*>(dlg);
if (thicknessDlg && thicknessDlg->getObject() != this->getObject())
thicknessDlg = 0; // another pad left open its task panel
if (dlg && !thicknessDlg) {
if (dlg->canClose())
Gui::Control().closeDialog();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
// start the edit dialog
if (thicknessDlg)
Gui::Control().showDialog(thicknessDlg);
else
Gui::Control().showDialog(new TaskThickness(static_cast<Part::Thickness*>(getObject())));
return true;
}
else {
return ViewProviderPart::setEdit(ModNum);
}
}
void ViewProviderThickness::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
// when pressing ESC make sure to close the dialog
Gui::Control().closeDialog();
}
else {
PartGui::ViewProviderPart::unsetEdit(ModNum);
}
}
std::vector<App::DocumentObject*> ViewProviderThickness::claimChildren() const
{
std::vector<App::DocumentObject*> child;
child.push_back(static_cast<Part::Thickness*>(getObject())->Faces.getValue());
return child;
}
bool ViewProviderThickness::onDelete(const std::vector<std::string> &)
{
// get the support and Sketch
Part::Thickness* thickness = static_cast<Part::Thickness*>(getObject());
App::DocumentObject* source = thickness->Faces.getValue();
if (source){
Gui::Application::Instance->getViewProvider(source)->show();
}
return true;
}

View File

@ -158,6 +158,26 @@ protected:
virtual void unsetEdit(int ModNum);
};
class ViewProviderThickness : public ViewProviderPart
{
PROPERTY_HEADER(PartGui::ViewProviderThickness);
public:
/// constructor
ViewProviderThickness();
/// destructor
virtual ~ViewProviderThickness();
/// grouping handling
std::vector<App::DocumentObject*> claimChildren(void)const;
void setupContextMenu(QMenu*, QObject*, const char*);
bool onDelete(const std::vector<std::string> &);
protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
};
} // namespace PartGui

View File

@ -72,7 +72,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Part_SimpleCopy" << "Part_RefineShape" << "Part_CheckGeometry" << "Separator"
<< "Part_Boolean" << "Part_CrossSections" << "Part_Extrude"
<< "Part_Revolve" << "Part_Mirror" << "Part_Fillet" << "Part_Chamfer"
<< "Part_RuledSurface" << "Part_Loft" << "Part_Sweep" << "Part_Offset";
<< "Part_RuledSurface" << "Part_Loft" << "Part_Sweep"
<< "Part_Offset" << "Part_Thickness";
return root;
}
@ -90,7 +91,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
tool->setCommand("Part tools");
*tool << "Part_Extrude" << "Part_Revolve" << "Part_Mirror" << "Part_Fillet"
<< "Part_Chamfer" << "Part_RuledSurface" << "Part_Loft" << "Part_Sweep"
<< "Part_Offset";
<< "Part_Offset" << "Part_Thickness";
Gui::ToolBarItem* boolop = new Gui::ToolBarItem(root);
boolop->setCommand("Boolean");