Allow booleans of bodies in PartDesign
This commit is contained in:
parent
ed2657380c
commit
638cfd2682
|
@ -52,6 +52,7 @@
|
||||||
#include "DatumPlane.h"
|
#include "DatumPlane.h"
|
||||||
#include "DatumLine.h"
|
#include "DatumLine.h"
|
||||||
#include "DatumPoint.h"
|
#include "DatumPoint.h"
|
||||||
|
#include "FeatureBoolean.h"
|
||||||
|
|
||||||
namespace PartDesign {
|
namespace PartDesign {
|
||||||
extern PyObject* initModule();
|
extern PyObject* initModule();
|
||||||
|
@ -102,6 +103,7 @@ PyMODINIT_FUNC init_PartDesign()
|
||||||
PartDesign::Plane ::init();
|
PartDesign::Plane ::init();
|
||||||
PartDesign::Line ::init();
|
PartDesign::Line ::init();
|
||||||
PartDesign::Point ::init();
|
PartDesign::Point ::init();
|
||||||
|
PartDesign::Boolean ::init();
|
||||||
|
|
||||||
PartDesign::Point::initHints();
|
PartDesign::Point::initHints();
|
||||||
PartDesign::Line ::initHints();
|
PartDesign::Line ::initHints();
|
||||||
|
|
|
@ -94,6 +94,8 @@ SET(FeaturesSketchBased_SRCS
|
||||||
FeatureSubtractive.cpp
|
FeatureSubtractive.cpp
|
||||||
FeatureHole.h
|
FeatureHole.h
|
||||||
FeatureHole.cpp
|
FeatureHole.cpp
|
||||||
|
FeatureBoolean.h
|
||||||
|
FeatureBoolean.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SOURCE_GROUP("SketchBasedFeatures" FILES ${FeaturesSketchBased_SRCS})
|
SOURCE_GROUP("SketchBasedFeatures" FILES ${FeaturesSketchBased_SRCS})
|
||||||
|
|
133
src/Mod/PartDesign/App/FeatureBoolean.cpp
Normal file
133
src/Mod/PartDesign/App/FeatureBoolean.cpp
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c)2013 Jan Rheinlaender <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_
|
||||||
|
# include <BRepAlgoAPI_Fuse.hxx>
|
||||||
|
# include <BRepAlgoAPI_Cut.hxx>
|
||||||
|
# include <BRepAlgoAPI_Common.hxx>
|
||||||
|
# include <BRepAlgoAPI_Section.hxx>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Body.h"
|
||||||
|
#include "FeatureBoolean.h"
|
||||||
|
|
||||||
|
#include <Base/Console.h>
|
||||||
|
#include <Base/Exception.h>
|
||||||
|
|
||||||
|
using namespace PartDesign;
|
||||||
|
|
||||||
|
namespace PartDesign {
|
||||||
|
|
||||||
|
PROPERTY_SOURCE(PartDesign::Boolean, PartDesign::Feature)
|
||||||
|
|
||||||
|
const char* Boolean::TypeEnums[]= {"Fuse","Cut","Common","Section",NULL};
|
||||||
|
|
||||||
|
Boolean::Boolean()
|
||||||
|
{
|
||||||
|
ADD_PROPERTY(Type,((long)0));
|
||||||
|
Type.setEnums(TypeEnums);
|
||||||
|
ADD_PROPERTY(Bodies,(0));
|
||||||
|
Bodies.setSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
short Boolean::mustExecute() const
|
||||||
|
{
|
||||||
|
if (Bodies.isTouched())
|
||||||
|
return 1;
|
||||||
|
return PartDesign::Feature::mustExecute();
|
||||||
|
}
|
||||||
|
|
||||||
|
App::DocumentObjectExecReturn *Boolean::execute(void)
|
||||||
|
{
|
||||||
|
std::vector<App::DocumentObject*> bodies = Bodies.getValues();
|
||||||
|
if (bodies.empty())
|
||||||
|
return App::DocumentObject::StdReturn;
|
||||||
|
|
||||||
|
// Get the first body
|
||||||
|
if (bodies.front() == NULL)
|
||||||
|
return new App::DocumentObjectExecReturn("No body for boolean");
|
||||||
|
PartDesign::Body* body = static_cast<PartDesign::Body*>(bodies.front());
|
||||||
|
const Part::TopoShape& bodyTopShape = body->Shape.getShape();
|
||||||
|
if (bodyTopShape._Shape.IsNull())
|
||||||
|
return new App::DocumentObjectExecReturn("Cannot do boolean operation on invalid body shape");
|
||||||
|
|
||||||
|
// create an untransformed copy of the body shape
|
||||||
|
Part::TopoShape bodyShape(bodyTopShape);
|
||||||
|
bodyShape.setTransform(Base::Matrix4D());
|
||||||
|
TopoDS_Shape result = bodyShape._Shape;
|
||||||
|
|
||||||
|
// Position this feature by the first body
|
||||||
|
this->Placement.setValue(body->Placement.getValue());
|
||||||
|
|
||||||
|
// Get the operation type
|
||||||
|
std::string type = Type.getValueAsString();
|
||||||
|
|
||||||
|
std::vector<App::DocumentObject*>::const_iterator b = bodies.begin();
|
||||||
|
b++;
|
||||||
|
|
||||||
|
for (; b != bodies.end(); b++)
|
||||||
|
{
|
||||||
|
// Extract the body shape
|
||||||
|
PartDesign::Body* body = static_cast<PartDesign::Body*>(*b);
|
||||||
|
TopoDS_Shape shape = body->Shape.getValue();
|
||||||
|
TopoDS_Shape boolOp;
|
||||||
|
|
||||||
|
if (type == "Fuse") {
|
||||||
|
BRepAlgoAPI_Fuse mkFuse(result, shape);
|
||||||
|
if (!mkFuse.IsDone())
|
||||||
|
return new App::DocumentObjectExecReturn("Fusion of bodies failed", *b);
|
||||||
|
// we have to get the solids (fuse sometimes creates compounds)
|
||||||
|
boolOp = this->getSolid(mkFuse.Shape());
|
||||||
|
// lets check if the result is a solid
|
||||||
|
if (boolOp.IsNull())
|
||||||
|
return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *b);
|
||||||
|
} else if (type == "Cut") {
|
||||||
|
BRepAlgoAPI_Cut mkCut(result, shape);
|
||||||
|
if (!mkCut.IsDone())
|
||||||
|
return new App::DocumentObjectExecReturn("Cut out of first body failed", *b);
|
||||||
|
boolOp = mkCut.Shape();
|
||||||
|
} else if (type == "Common") {
|
||||||
|
BRepAlgoAPI_Common mkCommon(result, shape);
|
||||||
|
if (!mkCommon.IsDone())
|
||||||
|
return new App::DocumentObjectExecReturn("Common operation with first body failed", *b);
|
||||||
|
boolOp = mkCommon.Shape();
|
||||||
|
} else if (type == "Section") {
|
||||||
|
BRepAlgoAPI_Section mkSection(result, shape);
|
||||||
|
if (!mkSection.IsDone())
|
||||||
|
return new App::DocumentObjectExecReturn("Section out of first body failed", *b);
|
||||||
|
// we have to get the solids
|
||||||
|
boolOp = this->getSolid(mkSection.Shape());
|
||||||
|
// lets check if the result is a solid
|
||||||
|
if (boolOp.IsNull())
|
||||||
|
return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *b);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = boolOp; // Use result of this operation for fuse/cut of next body
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Shape.setValue(result);
|
||||||
|
return App::DocumentObject::StdReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
69
src/Mod/PartDesign/App/FeatureBoolean.h
Normal file
69
src/Mod/PartDesign/App/FeatureBoolean.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c)2013 Jan Rheinlaender <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 PARTDESIGN_FeatureBoolean_H
|
||||||
|
#define PARTDESIGN_FeatureBoolean_H
|
||||||
|
|
||||||
|
#include <App/PropertyStandard.h>
|
||||||
|
#include "Feature.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace PartDesign
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract superclass of all features that are created by transformation of another feature
|
||||||
|
* Transformations are translation, rotation and mirroring
|
||||||
|
*/
|
||||||
|
class PartDesignExport Boolean : public PartDesign::Feature
|
||||||
|
{
|
||||||
|
PROPERTY_HEADER(PartDesign::Boolean);
|
||||||
|
|
||||||
|
public:
|
||||||
|
Boolean();
|
||||||
|
|
||||||
|
/// The type of the boolean operation
|
||||||
|
App::PropertyEnumeration Type;
|
||||||
|
/// The bodies for the operation
|
||||||
|
App::PropertyLinkList Bodies;
|
||||||
|
|
||||||
|
/** @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::ViewProviderBoolean";
|
||||||
|
}
|
||||||
|
//@}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char* TypeEnums[];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace PartDesign
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PARTDESIGN_FeatureBoolean_H
|
|
@ -51,6 +51,7 @@
|
||||||
#include "ViewProviderDatumPoint.h"
|
#include "ViewProviderDatumPoint.h"
|
||||||
#include "ViewProviderDatumLine.h"
|
#include "ViewProviderDatumLine.h"
|
||||||
#include "ViewProviderDatumPlane.h"
|
#include "ViewProviderDatumPlane.h"
|
||||||
|
#include "ViewProviderBoolean.h"
|
||||||
|
|
||||||
// use a different name to CreateCommand()
|
// use a different name to CreateCommand()
|
||||||
void CreatePartDesignCommands(void);
|
void CreatePartDesignCommands(void);
|
||||||
|
@ -126,6 +127,7 @@ PyMODINIT_FUNC initPartDesignGui()
|
||||||
PartDesignGui::ViewProviderDatumPoint ::init();
|
PartDesignGui::ViewProviderDatumPoint ::init();
|
||||||
PartDesignGui::ViewProviderDatumLine ::init();
|
PartDesignGui::ViewProviderDatumLine ::init();
|
||||||
PartDesignGui::ViewProviderDatumPlane ::init();
|
PartDesignGui::ViewProviderDatumPlane ::init();
|
||||||
|
PartDesignGui::ViewProviderBoolean ::init();
|
||||||
|
|
||||||
// add resources and reloads the translators
|
// add resources and reloads the translators
|
||||||
loadPartDesignResource();
|
loadPartDesignResource();
|
||||||
|
|
|
@ -46,6 +46,7 @@ set(PartDesignGui_MOC_HDRS
|
||||||
TaskScaledParameters.h
|
TaskScaledParameters.h
|
||||||
TaskMultiTransformParameters.h
|
TaskMultiTransformParameters.h
|
||||||
TaskDatumParameters.h
|
TaskDatumParameters.h
|
||||||
|
TaskBooleanParameters.h
|
||||||
)
|
)
|
||||||
fc_wrap_cpp(PartDesignGui_MOC_SRCS ${PartDesignGui_MOC_HDRS})
|
fc_wrap_cpp(PartDesignGui_MOC_SRCS ${PartDesignGui_MOC_HDRS})
|
||||||
SOURCE_GROUP("Moc" FILES ${PartDesignGui_MOC_SRCS})
|
SOURCE_GROUP("Moc" FILES ${PartDesignGui_MOC_SRCS})
|
||||||
|
@ -59,6 +60,7 @@ set(PartDesignGui_UIC_SRCS
|
||||||
TaskChamferParameters.ui
|
TaskChamferParameters.ui
|
||||||
TaskFilletParameters.ui
|
TaskFilletParameters.ui
|
||||||
TaskDraftParameters.ui
|
TaskDraftParameters.ui
|
||||||
|
TaskBooleanParameters.ui
|
||||||
TaskHoleParameters.ui
|
TaskHoleParameters.ui
|
||||||
TaskRevolutionParameters.ui
|
TaskRevolutionParameters.ui
|
||||||
TaskGrooveParameters.ui
|
TaskGrooveParameters.ui
|
||||||
|
@ -113,6 +115,8 @@ SET(PartDesignGuiViewProvider_SRCS
|
||||||
ViewProviderDatumLine.h
|
ViewProviderDatumLine.h
|
||||||
ViewProviderDatumPlane.cpp
|
ViewProviderDatumPlane.cpp
|
||||||
ViewProviderDatumPlane.h
|
ViewProviderDatumPlane.h
|
||||||
|
ViewProviderBoolean.cpp
|
||||||
|
ViewProviderBoolean.h
|
||||||
)
|
)
|
||||||
SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS})
|
SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS})
|
||||||
|
|
||||||
|
@ -171,6 +175,9 @@ SET(PartDesignGuiTaskDlgs_SRCS
|
||||||
TaskDatumParameters.ui
|
TaskDatumParameters.ui
|
||||||
TaskDatumParameters.cpp
|
TaskDatumParameters.cpp
|
||||||
TaskDatumParameters.h
|
TaskDatumParameters.h
|
||||||
|
TaskBooleanParameters.ui
|
||||||
|
TaskBooleanParameters.cpp
|
||||||
|
TaskBooleanParameters.h
|
||||||
)
|
)
|
||||||
SOURCE_GROUP("TaskDialogs" FILES ${PartDesignGuiTaskDlgs_SRCS})
|
SOURCE_GROUP("TaskDialogs" FILES ${PartDesignGuiTaskDlgs_SRCS})
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
#include <Gui/MainWindow.h>
|
#include <Gui/MainWindow.h>
|
||||||
#include <Gui/FileDialog.h>
|
#include <Gui/FileDialog.h>
|
||||||
#include <Gui/SelectionFilter.h>
|
#include <Gui/SelectionFilter.h>
|
||||||
|
#include <Gui/SelectionObject.h>
|
||||||
#include <Gui/ViewProvider.h>
|
#include <Gui/ViewProvider.h>
|
||||||
#include <Gui/Tree.h>
|
#include <Gui/Tree.h>
|
||||||
#include <Gui/Document.h>
|
#include <Gui/Document.h>
|
||||||
|
@ -1593,6 +1594,66 @@ bool CmdPartDesignMultiTransform::isActive(void)
|
||||||
return hasActiveDocument();
|
return hasActiveDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
// PartDesign_Boolean
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
/* Boolean commands =======================================================*/
|
||||||
|
DEF_STD_CMD_A(CmdPartDesignBoolean);
|
||||||
|
|
||||||
|
CmdPartDesignBoolean::CmdPartDesignBoolean()
|
||||||
|
:Command("PartDesign_Boolean")
|
||||||
|
{
|
||||||
|
sAppModule = "PartDesign";
|
||||||
|
sGroup = QT_TR_NOOP("PartDesign");
|
||||||
|
sMenuText = QT_TR_NOOP("Boolean operation");
|
||||||
|
sToolTipText = QT_TR_NOOP("Boolean operation with two or more boies");
|
||||||
|
sWhatsThis = sToolTipText;
|
||||||
|
sStatusTip = sToolTipText;
|
||||||
|
sPixmap = "PartDesign_Boolean";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CmdPartDesignBoolean::activated(int iMsg)
|
||||||
|
{
|
||||||
|
Gui::SelectionFilter BodyFilter("SELECT PartDesign::Body COUNT 1..");
|
||||||
|
std::string bodyString("[");
|
||||||
|
|
||||||
|
if (BodyFilter.match()) {
|
||||||
|
std::vector<App::DocumentObject*> bodies;
|
||||||
|
for (std::vector<std::vector<Gui::SelectionObject> >::iterator i = BodyFilter.Result.begin();
|
||||||
|
i != BodyFilter.Result.end(); i++) {
|
||||||
|
for (std::vector<Gui::SelectionObject>::iterator j = i->begin(); j != i->end(); j++) {
|
||||||
|
bodies.push_back(j->getObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++)
|
||||||
|
bodyString += std::string("App.activeDocument().") + (*b)->getNameInDocument() + ",";
|
||||||
|
bodyString += "]";
|
||||||
|
} else {
|
||||||
|
bodyString = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FeatName = getUniqueObjectName("Boolean");
|
||||||
|
|
||||||
|
openCommand("Create Boolean");
|
||||||
|
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Boolean','%s')",FeatName.c_str());
|
||||||
|
if (!bodyString.empty())
|
||||||
|
doCommand(Doc,"App.activeDocument().%s.Bodies = %s",FeatName.c_str(),bodyString.c_str());
|
||||||
|
//doCommand(Gui,"App.activeDocument().recompute()");
|
||||||
|
//doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str());
|
||||||
|
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CmdPartDesignBoolean::isActive(void)
|
||||||
|
{
|
||||||
|
if (getActiveGuiDocument())
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
// Initialization
|
// Initialization
|
||||||
|
@ -1627,4 +1688,6 @@ void CreatePartDesignCommands(void)
|
||||||
rcCmdMgr.addCommand(new CmdPartDesignPolarPattern());
|
rcCmdMgr.addCommand(new CmdPartDesignPolarPattern());
|
||||||
//rcCmdMgr.addCommand(new CmdPartDesignScaled());
|
//rcCmdMgr.addCommand(new CmdPartDesignScaled());
|
||||||
rcCmdMgr.addCommand(new CmdPartDesignMultiTransform());
|
rcCmdMgr.addCommand(new CmdPartDesignMultiTransform());
|
||||||
|
|
||||||
|
rcCmdMgr.addCommand(new CmdPartDesignBoolean());
|
||||||
}
|
}
|
||||||
|
|
355
src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp
Normal file
355
src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp
Normal file
|
@ -0,0 +1,355 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* 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_
|
||||||
|
# include <QMessageBox>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ui_TaskBooleanParameters.h"
|
||||||
|
#include "TaskBooleanParameters.h"
|
||||||
|
#include "Workbench.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 <Gui/MainWindow.h>
|
||||||
|
#include <Mod/PartDesign/App/FeatureBoolean.h>
|
||||||
|
#include <Mod/PartDesign/App/Body.h>
|
||||||
|
#include <Mod/Sketcher/App/SketchObject.h>
|
||||||
|
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||||
|
|
||||||
|
using namespace PartDesignGui;
|
||||||
|
using namespace Gui;
|
||||||
|
|
||||||
|
/* TRANSLATOR PartDesignGui::TaskBooleanParameters */
|
||||||
|
|
||||||
|
TaskBooleanParameters::TaskBooleanParameters(ViewProviderBoolean *BooleanView,QWidget *parent)
|
||||||
|
: TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Boolean"),tr("Boolean parameters"),true, parent),BooleanView(BooleanView)
|
||||||
|
{
|
||||||
|
selectionMode = none;
|
||||||
|
|
||||||
|
// we need a separate container widget to add all controls to
|
||||||
|
proxy = new QWidget(this);
|
||||||
|
ui = new Ui_TaskBooleanParameters();
|
||||||
|
ui->setupUi(proxy);
|
||||||
|
QMetaObject::connectSlotsByName(this);
|
||||||
|
|
||||||
|
connect(ui->buttonBodyAdd, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(onButtonBodyAdd(bool)));
|
||||||
|
connect(ui->buttonBodyRemove, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(onButtonBodyRemove(bool)));
|
||||||
|
connect(ui->comboType, SIGNAL(currentIndexChanged(int)),
|
||||||
|
this, SLOT(onTypeChanged(int)));
|
||||||
|
|
||||||
|
this->groupLayout()->addWidget(proxy);
|
||||||
|
|
||||||
|
PartDesign::Boolean* pcBoolean = static_cast<PartDesign::Boolean*>(BooleanView->getObject());
|
||||||
|
std::vector<App::DocumentObject*> bodies = pcBoolean->Bodies.getValues();
|
||||||
|
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++)
|
||||||
|
{
|
||||||
|
ui->listWidgetBodies->insertItem(0, QString::fromAscii((*b)->getNameInDocument()));
|
||||||
|
}
|
||||||
|
// Create context menu
|
||||||
|
QAction* action = new QAction(tr("Remove"), this);
|
||||||
|
ui->listWidgetBodies->addAction(action);
|
||||||
|
connect(action, SIGNAL(triggered()), this, SLOT(onBodyDeleted()));
|
||||||
|
ui->listWidgetBodies->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||||
|
|
||||||
|
int index = pcBoolean->Type.getValue();
|
||||||
|
ui->comboType->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||||
|
{
|
||||||
|
if (selectionMode == none)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||||
|
if (strcmp(msg.pDocName, BooleanView->getObject()->getDocument()->getName()) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PartDesign::Boolean* pcBoolean = static_cast<PartDesign::Boolean*>(BooleanView->getObject());
|
||||||
|
std::string body(msg.pObjectName);
|
||||||
|
if (body.empty())
|
||||||
|
return;
|
||||||
|
App::DocumentObject* pcBody = pcBoolean->getDocument()->getObject(body.c_str());
|
||||||
|
if (pcBody == NULL)
|
||||||
|
return;
|
||||||
|
if (!pcBody->getTypeId().isDerivedFrom(PartDesign::Body::getClassTypeId())) {
|
||||||
|
pcBody = PartDesign::Body::findBodyOf(pcBody);
|
||||||
|
if (pcBody == NULL)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<App::DocumentObject*> bodies = pcBoolean->Bodies.getValues();
|
||||||
|
|
||||||
|
if (selectionMode == bodyAdd) {
|
||||||
|
if (std::find(bodies.begin(), bodies.end(), pcBody) == bodies.end()) {
|
||||||
|
bodies.push_back(pcBody);
|
||||||
|
pcBoolean->Bodies.setValues(bodies);
|
||||||
|
ui->listWidgetBodies->insertItem(ui->listWidgetBodies->count(),
|
||||||
|
QString::fromStdString(pcBody->getNameInDocument()));
|
||||||
|
|
||||||
|
pcBoolean->getDocument()->recomputeFeature(pcBoolean);
|
||||||
|
ui->buttonBodyAdd->setChecked(false);
|
||||||
|
exitSelectionMode();
|
||||||
|
|
||||||
|
// Hide the bodies if there are more than two
|
||||||
|
if (bodies.size() == 2) {
|
||||||
|
// Hide both bodies
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(bodies.front()));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->hide();
|
||||||
|
vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(bodies.back()));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->hide();
|
||||||
|
BooleanView->show();
|
||||||
|
} else {
|
||||||
|
// Hide newly added body
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(bodies.back()));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (selectionMode == bodyRemove) {
|
||||||
|
std::vector<App::DocumentObject*>::iterator b = std::find(bodies.begin(), bodies.end(), pcBody);
|
||||||
|
if (b != bodies.end()) {
|
||||||
|
bodies.erase(b);
|
||||||
|
pcBoolean->Bodies.setValues(bodies);
|
||||||
|
QList<QListWidgetItem*> items = ui->listWidgetBodies->findItems(QString::fromStdString(body), Qt::MatchExactly);
|
||||||
|
if (!items.empty()) {
|
||||||
|
for (QList<QListWidgetItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
|
||||||
|
QListWidgetItem* it = ui->listWidgetBodies->takeItem(ui->listWidgetBodies->row(*i));
|
||||||
|
delete it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pcBoolean->getDocument()->recomputeFeature(pcBoolean);
|
||||||
|
ui->buttonBodyRemove->setChecked(false);
|
||||||
|
exitSelectionMode();
|
||||||
|
|
||||||
|
// Make bodies visible again
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(*b));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->show();
|
||||||
|
if (bodies.size() == 1) {
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(bodies.front()));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->show();
|
||||||
|
BooleanView->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::onButtonBodyAdd(bool checked)
|
||||||
|
{
|
||||||
|
if (checked) {
|
||||||
|
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||||
|
if (doc != NULL)
|
||||||
|
doc->setHide(BooleanView->getObject()->getNameInDocument());
|
||||||
|
selectionMode = bodyAdd;
|
||||||
|
Gui::Selection().clearSelection();
|
||||||
|
} else {
|
||||||
|
exitSelectionMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::onButtonBodyRemove(bool checked)
|
||||||
|
{
|
||||||
|
if (checked) {
|
||||||
|
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||||
|
if (doc != NULL)
|
||||||
|
doc->setHide(BooleanView->getObject()->getNameInDocument());
|
||||||
|
selectionMode = bodyRemove;
|
||||||
|
Gui::Selection().clearSelection();
|
||||||
|
} else {
|
||||||
|
exitSelectionMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::onTypeChanged(int index)
|
||||||
|
{
|
||||||
|
PartDesign::Boolean* pcBoolean = static_cast<PartDesign::Boolean*>(BooleanView->getObject());
|
||||||
|
|
||||||
|
switch (index) {
|
||||||
|
case 0: pcBoolean->Type.setValue("Fuse"); break;
|
||||||
|
case 1: pcBoolean->Type.setValue("Cut"); break;
|
||||||
|
case 2: pcBoolean->Type.setValue("Common"); break;
|
||||||
|
case 3: pcBoolean->Type.setValue("Section"); break;
|
||||||
|
default: pcBoolean->Type.setValue("Fuse");
|
||||||
|
}
|
||||||
|
|
||||||
|
pcBoolean->getDocument()->recomputeFeature(pcBoolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<std::string> TaskBooleanParameters::getBodies(void) const
|
||||||
|
{
|
||||||
|
std::vector<std::string> result;
|
||||||
|
for (int i = 0; i < ui->listWidgetBodies->count(); i++)
|
||||||
|
result.push_back(ui->listWidgetBodies->item(i)->text().toStdString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TaskBooleanParameters::getType(void) const
|
||||||
|
{
|
||||||
|
return ui->comboType->currentIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::onBodyDeleted(void)
|
||||||
|
{
|
||||||
|
PartDesign::Boolean* pcBoolean = static_cast<PartDesign::Boolean*>(BooleanView->getObject());
|
||||||
|
std::vector<App::DocumentObject*> bodies = pcBoolean->Bodies.getValues();
|
||||||
|
int index = ui->listWidgetBodies->currentRow();
|
||||||
|
if (index > bodies.size())
|
||||||
|
return;
|
||||||
|
App::DocumentObject* body = bodies[index];
|
||||||
|
bodies.erase(bodies.begin() + ui->listWidgetBodies->currentRow());
|
||||||
|
pcBoolean->Bodies.setValues(bodies);
|
||||||
|
ui->listWidgetBodies->model()->removeRow(ui->listWidgetBodies->currentRow());
|
||||||
|
pcBoolean->getDocument()->recomputeFeature(pcBoolean);
|
||||||
|
|
||||||
|
// Make bodies visible again
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(body));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->show();
|
||||||
|
if (bodies.size() == 1) {
|
||||||
|
Gui::ViewProviderDocumentObject* vp = dynamic_cast<Gui::ViewProviderDocumentObject*>(
|
||||||
|
Gui::Application::Instance->getViewProvider(bodies.front()));
|
||||||
|
if (vp != NULL)
|
||||||
|
vp->show();
|
||||||
|
BooleanView->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskBooleanParameters::~TaskBooleanParameters()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::changeEvent(QEvent *e)
|
||||||
|
{
|
||||||
|
TaskBox::changeEvent(e);
|
||||||
|
if (e->type() == QEvent::LanguageChange) {
|
||||||
|
ui->comboType->blockSignals(true);
|
||||||
|
int index = ui->comboType->currentIndex();
|
||||||
|
ui->retranslateUi(proxy);
|
||||||
|
ui->comboType->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskBooleanParameters::exitSelectionMode()
|
||||||
|
{
|
||||||
|
selectionMode = none;
|
||||||
|
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||||
|
if (doc != NULL)
|
||||||
|
doc->setShow(BooleanView->getObject()->getNameInDocument());
|
||||||
|
}
|
||||||
|
|
||||||
|
//**************************************************************************
|
||||||
|
//**************************************************************************
|
||||||
|
// TaskDialog
|
||||||
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
TaskDlgBooleanParameters::TaskDlgBooleanParameters(ViewProviderBoolean *BooleanView)
|
||||||
|
: TaskDialog(),BooleanView(BooleanView)
|
||||||
|
{
|
||||||
|
assert(BooleanView);
|
||||||
|
parameter = new TaskBooleanParameters(BooleanView);
|
||||||
|
|
||||||
|
Content.push_back(parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskDlgBooleanParameters::~TaskDlgBooleanParameters()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//==== calls from the TaskView ===============================================================
|
||||||
|
|
||||||
|
|
||||||
|
void TaskDlgBooleanParameters::open()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskDlgBooleanParameters::clicked(int)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskDlgBooleanParameters::accept()
|
||||||
|
{
|
||||||
|
std::string name = BooleanView->getObject()->getNameInDocument();
|
||||||
|
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||||
|
if (doc != NULL)
|
||||||
|
doc->setShow(name.c_str());
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::vector<std::string> bodies = parameter->getBodies();
|
||||||
|
std::stringstream str;
|
||||||
|
str << "App.ActiveDocument." << name.c_str() << ".Bodies = [";
|
||||||
|
for (std::vector<std::string>::const_iterator it = bodies.begin(); it != bodies.end(); ++it)
|
||||||
|
str << "App.ActiveDocument." << *it << ",";
|
||||||
|
str << "]";
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
|
||||||
|
}
|
||||||
|
catch (const Base::Exception& e) {
|
||||||
|
QMessageBox::warning(parameter, tr("Boolean: Accept: Input error"), QString::fromAscii(e.what()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),parameter->getType());
|
||||||
|
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
|
||||||
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||||
|
Gui::Command::commitCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TaskDlgBooleanParameters::reject()
|
||||||
|
{
|
||||||
|
// roll back the done things
|
||||||
|
Gui::Command::abortCommand();
|
||||||
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "moc_TaskBooleanParameters.cpp"
|
118
src/Mod/PartDesign/Gui/TaskBooleanParameters.h
Normal file
118
src/Mod/PartDesign/Gui/TaskBooleanParameters.h
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2013 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_TaskBooleanParameters_H
|
||||||
|
#define GUI_TASKVIEW_TaskBooleanParameters_H
|
||||||
|
|
||||||
|
#include <Gui/TaskView/TaskView.h>
|
||||||
|
#include <Gui/Selection.h>
|
||||||
|
#include <Gui/TaskView/TaskDialog.h>
|
||||||
|
|
||||||
|
#include "ViewProviderBoolean.h"
|
||||||
|
|
||||||
|
class Ui_TaskBooleanParameters;
|
||||||
|
|
||||||
|
namespace App {
|
||||||
|
class Property;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Gui {
|
||||||
|
class ViewProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace PartDesignGui {
|
||||||
|
|
||||||
|
class TaskBooleanParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TaskBooleanParameters(ViewProviderBoolean *BooleanView, QWidget *parent=0);
|
||||||
|
~TaskBooleanParameters();
|
||||||
|
|
||||||
|
const std::vector<std::string> getBodies(void) const;
|
||||||
|
int getType(void) const;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onButtonBodyAdd(const bool checked);
|
||||||
|
void onButtonBodyRemove(const bool checked);
|
||||||
|
void onBodyDeleted(void);
|
||||||
|
void onTypeChanged(int index);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void exitSelectionMode();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent(QEvent *e);
|
||||||
|
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget* proxy;
|
||||||
|
Ui_TaskBooleanParameters* ui;
|
||||||
|
ViewProviderBoolean *BooleanView;
|
||||||
|
|
||||||
|
enum selectionModes { none, bodyAdd, bodyRemove };
|
||||||
|
selectionModes selectionMode;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// simulation dialog for the TaskView
|
||||||
|
class TaskDlgBooleanParameters : public Gui::TaskView::TaskDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TaskDlgBooleanParameters(ViewProviderBoolean *BooleanView);
|
||||||
|
~TaskDlgBooleanParameters();
|
||||||
|
|
||||||
|
ViewProviderBoolean* getBooleanView() const
|
||||||
|
{ return BooleanView; }
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
ViewProviderBoolean *BooleanView;
|
||||||
|
|
||||||
|
TaskBooleanParameters *parameter;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace PartDesignGui
|
||||||
|
|
||||||
|
#endif // GUI_TASKVIEW_TASKAPPERANCE_H
|
72
src/Mod/PartDesign/Gui/TaskBooleanParameters.ui
Normal file
72
src/Mod/PartDesign/Gui/TaskBooleanParameters.ui
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>PartDesignGui::TaskBooleanParameters</class>
|
||||||
|
<widget class="QWidget" name="PartDesignGui::TaskBooleanParameters">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>209</width>
|
||||||
|
<height>185</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="buttonBodyAdd">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add body</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="buttonBodyRemove">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove body</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="listWidgetBodies"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboType">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Fuse</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Cut</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Common</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Section</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
124
src/Mod/PartDesign/Gui/ViewProviderBoolean.cpp
Normal file
124
src/Mod/PartDesign/Gui/ViewProviderBoolean.cpp
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2013 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_
|
||||||
|
# include <QMessageBox>
|
||||||
|
# include <QAction>
|
||||||
|
# include <QMenu>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ViewProviderBoolean.h"
|
||||||
|
#include "TaskBooleanParameters.h"
|
||||||
|
#include <Mod/PartDesign/App/FeatureBoolean.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::ViewProviderBoolean,PartDesignGui::ViewProvider)
|
||||||
|
|
||||||
|
ViewProviderBoolean::ViewProviderBoolean()
|
||||||
|
{
|
||||||
|
sPixmap = "PartDesign_Boolean.svg";
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewProviderBoolean::~ViewProviderBoolean()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ViewProviderBoolean::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||||
|
{
|
||||||
|
QAction* act;
|
||||||
|
act = menu->addAction(QObject::tr("Edit boolean"), receiver, member);
|
||||||
|
act->setData(QVariant((int)ViewProvider::Default));
|
||||||
|
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ViewProviderBoolean::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();
|
||||||
|
TaskDlgBooleanParameters *booleanDlg = qobject_cast<TaskDlgBooleanParameters *>(dlg);
|
||||||
|
if (booleanDlg && booleanDlg->getBooleanView() != this)
|
||||||
|
booleanDlg = 0; // another pad left open its task panel
|
||||||
|
if (dlg && !booleanDlg) {
|
||||||
|
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();
|
||||||
|
|
||||||
|
// always change to PartDesign WB, remember where we come from
|
||||||
|
oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||||
|
|
||||||
|
// start the edit dialog
|
||||||
|
if (booleanDlg)
|
||||||
|
Gui::Control().showDialog(booleanDlg);
|
||||||
|
else
|
||||||
|
Gui::Control().showDialog(new TaskDlgBooleanParameters(this));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return PartGui::ViewProviderPart::setEdit(ModNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<App::DocumentObject*> ViewProviderBoolean::claimChildren(void)const
|
||||||
|
{
|
||||||
|
return static_cast<PartDesign::Boolean*>(getObject())->Bodies.getValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ViewProviderBoolean::onDelete(const std::vector<std::string> &s)
|
||||||
|
{
|
||||||
|
PartDesign::Boolean* pcBoolean = static_cast<PartDesign::Boolean*>(getObject());
|
||||||
|
|
||||||
|
// if abort command deleted the object the bodies are visible again
|
||||||
|
std::vector<App::DocumentObject*> bodies = pcBoolean->Bodies.getValues();
|
||||||
|
for (std::vector<App::DocumentObject*>::const_iterator b = bodies.begin(); b != bodies.end(); b++) {
|
||||||
|
if (*b && Gui::Application::Instance->getViewProvider(*b))
|
||||||
|
Gui::Application::Instance->getViewProvider(*b)->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ViewProvider::onDelete(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
56
src/Mod/PartDesign/Gui/ViewProviderBoolean.h
Normal file
56
src/Mod/PartDesign/Gui/ViewProviderBoolean.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2013 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_ViewProviderBoolean_H
|
||||||
|
#define PARTGUI_ViewProviderBoolean_H
|
||||||
|
|
||||||
|
#include "ViewProvider.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace PartDesignGui {
|
||||||
|
|
||||||
|
class PartDesignGuiExport ViewProviderBoolean : public ViewProvider
|
||||||
|
{
|
||||||
|
PROPERTY_HEADER(PartDesignGui::ViewProviderBoolean);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// constructor
|
||||||
|
ViewProviderBoolean();
|
||||||
|
/// destructor
|
||||||
|
virtual ~ViewProviderBoolean();
|
||||||
|
|
||||||
|
/// grouping handling
|
||||||
|
void setupContextMenu(QMenu*, QObject*, const char*);
|
||||||
|
std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||||
|
|
||||||
|
virtual bool onDelete(const std::vector<std::string> &);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool setEdit(int ModNum);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace PartDesignGui
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PARTGUI_ViewProviderBoolean_H
|
|
@ -342,6 +342,16 @@ void Workbench::activated()
|
||||||
"Part_Box"
|
"Part_Box"
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const char* Body2[] = {
|
||||||
|
"PartDesign_Boolean",
|
||||||
|
0};
|
||||||
|
Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
|
||||||
|
"SELECT PartDesign::Body COUNT 1..",
|
||||||
|
Body2,
|
||||||
|
"Start Boolean",
|
||||||
|
"Part_Box"
|
||||||
|
));
|
||||||
|
|
||||||
const char* Plane1[] = {
|
const char* Plane1[] = {
|
||||||
"PartDesign_NewSketch",
|
"PartDesign_NewSketch",
|
||||||
"PartDesign_Plane",
|
"PartDesign_Plane",
|
||||||
|
@ -520,7 +530,10 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||||
<< "PartDesign_LinearPattern"
|
<< "PartDesign_LinearPattern"
|
||||||
<< "PartDesign_PolarPattern"
|
<< "PartDesign_PolarPattern"
|
||||||
// << "PartDesign_Scaled"
|
// << "PartDesign_Scaled"
|
||||||
<< "PartDesign_MultiTransform";
|
<< "PartDesign_MultiTransform"
|
||||||
|
<< "Separator"
|
||||||
|
<< "PartDesign_Boolean";
|
||||||
|
|
||||||
// For 0.13 a couple of python packages like numpy, matplotlib and others
|
// For 0.13 a couple of python packages like numpy, matplotlib and others
|
||||||
// are not deployed with the installer on Windows. Thus, the WizardShaft is
|
// are not deployed with the installer on Windows. Thus, the WizardShaft is
|
||||||
// not deployed either hence the check for the existence of the command.
|
// not deployed either hence the check for the existence of the command.
|
||||||
|
@ -566,7 +579,9 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
|
||||||
<< "PartDesign_LinearPattern"
|
<< "PartDesign_LinearPattern"
|
||||||
<< "PartDesign_PolarPattern"
|
<< "PartDesign_PolarPattern"
|
||||||
// << "PartDesign_Scaled"
|
// << "PartDesign_Scaled"
|
||||||
<< "PartDesign_MultiTransform";
|
<< "PartDesign_MultiTransform"
|
||||||
|
<< "Separator"
|
||||||
|
<< "PartDesign_Boolean";
|
||||||
|
|
||||||
Gui::ToolBarItem* geom = new Gui::ToolBarItem(root);
|
Gui::ToolBarItem* geom = new Gui::ToolBarItem(root);
|
||||||
geom->setCommand("Sketcher geometries");
|
geom->setCommand("Sketcher geometries");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user