Merge branch 'master' of git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad

This commit is contained in:
jrheinlaender 2012-09-21 07:49:20 +04:30
commit 8d8715e55a
33 changed files with 1211 additions and 675 deletions

View File

@ -45,7 +45,7 @@ Feature::Feature()
{ {
} }
TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape) const TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape)
{ {
if (shape.IsNull()) if (shape.IsNull())
Standard_Failure::Raise("Shape is null"); Standard_Failure::Raise("Shape is null");
@ -58,7 +58,7 @@ TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape) const
return TopoDS_Shape(); return TopoDS_Shape();
} }
const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f) const const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
{ {
if (!f.Infinite()) { if (!f.Infinite()) {
TopExp_Explorer exp; TopExp_Explorer exp;

View File

@ -49,10 +49,10 @@ protected:
/** /**
* Get a solid of the given shape. If no solid is found an exception is raised. * Get a solid of the given shape. If no solid is found an exception is raised.
*/ */
TopoDS_Shape getSolid(const TopoDS_Shape&) const; static TopoDS_Shape getSolid(const TopoDS_Shape&);
/// Grab any point from the given face /// Grab any point from the given face
const gp_Pnt getPointFromFace(const TopoDS_Face& f) const; static const gp_Pnt getPointFromFace(const TopoDS_Face& f);
}; };

View File

@ -28,6 +28,7 @@
# include <BRepAlgoAPI_Cut.hxx> # include <BRepAlgoAPI_Cut.hxx>
# include <BRep_Builder.hxx> # include <BRep_Builder.hxx>
# include <TopExp.hxx> # include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx> # include <TopTools_IndexedMapOfShape.hxx>
# include <Bnd_Box.hxx> # include <Bnd_Box.hxx>
# include <BRepBndLib.hxx> # include <BRepBndLib.hxx>
@ -50,7 +51,7 @@ namespace PartDesign {
PROPERTY_SOURCE(PartDesign::Transformed, PartDesign::Feature) PROPERTY_SOURCE(PartDesign::Transformed, PartDesign::Feature)
Transformed::Transformed() Transformed::Transformed() : rejected(0)
{ {
ADD_PROPERTY(Originals,(0)); ADD_PROPERTY(Originals,(0));
Originals.setSize(0); Originals.setSize(0);
@ -58,12 +59,12 @@ Transformed::Transformed()
void Transformed::positionBySupport(void) void Transformed::positionBySupport(void)
{ {
Part::Feature *support = static_cast<Part::Feature*>(getOriginalObject()); Part::Feature *support = static_cast<Part::Feature*>(getSupportObject());
if ((support != NULL) && support->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) if ((support != NULL) && support->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
this->Placement.setValue(support->Placement.getValue()); this->Placement.setValue(support->Placement.getValue());
} }
App::DocumentObject* Transformed::getOriginalObject() const App::DocumentObject* Transformed::getSupportObject() const
{ {
if (!Originals.getValues().empty()) if (!Originals.getValues().empty())
return Originals.getValues().front(); return Originals.getValues().front();
@ -80,6 +81,8 @@ short Transformed::mustExecute() const
App::DocumentObjectExecReturn *Transformed::execute(void) App::DocumentObjectExecReturn *Transformed::execute(void)
{ {
rejected.clear();
std::vector<App::DocumentObject*> originals = Originals.getValues(); std::vector<App::DocumentObject*> originals = Originals.getValues();
if (originals.empty()) // typically InsideMultiTransform if (originals.empty()) // typically InsideMultiTransform
return App::DocumentObject::StdReturn; return App::DocumentObject::StdReturn;
@ -101,10 +104,10 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
// NOTE: Because of the way we define the support, FeatureTransformed can only work on // NOTE: Because of the way we define the support, FeatureTransformed can only work on
// one Body feature at a time // one Body feature at a time
// TODO: Currently, the support is simply the first Original. Change this to the Body feature later // TODO: Currently, the support is simply the first Original. Change this to the Body feature later
Part::Feature* supportFeature = static_cast<Part::Feature*>(originals.front()); Part::Feature* supportFeature = static_cast<Part::Feature*>(getSupportObject());
const Part::TopoShape& supportTopShape = supportFeature->Shape.getShape(); const Part::TopoShape& supportTopShape = supportFeature->Shape.getShape();
if (supportTopShape._Shape.IsNull()) if (supportTopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot transform invalid shape"); return new App::DocumentObjectExecReturn("Cannot transform invalid support shape");
// create an untransformed copy of the support shape // create an untransformed copy of the support shape
Part::TopoShape supportShape(supportTopShape); Part::TopoShape supportShape(supportTopShape);
@ -162,9 +165,10 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
Bnd_Box transformed_bb; Bnd_Box transformed_bb;
BRepBndLib::Add(mkTrf.Shape(), transformed_bb); BRepBndLib::Add(mkTrf.Shape(), transformed_bb);
if (support_bb.Distance(transformed_bb) > Precision::Confusion()) { if (support_bb.Distance(transformed_bb) > Precision::Confusion()) {
Base::Console().Warning("Transformed shape does not intersect original %s: Removed\n", (*o)->getNameInDocument()); Base::Console().Warning("Transformed shape does not intersect support %s: Removed\n", (*o)->getNameInDocument());
// Note: The removal happens in getSolid() after the fuse. If we remove here, // Note: The removal happens in getSolid() after the fuse. If we remove here,
// the histories get messed up and we get a crash // the histories get messed up and we get a crash
rejected.push_back(*t);
} }
builder.Add(transformedShapes, mkTrf.Shape()); builder.Add(transformedShapes, mkTrf.Shape());
v_transformedShapes.push_back(mkTrf.Shape()); v_transformedShapes.push_back(mkTrf.Shape());
@ -178,7 +182,7 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
Bnd_Box transformed_bb; Bnd_Box transformed_bb;
BRepBndLib::Add(trfShape, transformed_bb); BRepBndLib::Add(trfShape, transformed_bb);
if (support_bb.Distance(transformed_bb) > Precision::Confusion()) { if (support_bb.Distance(transformed_bb) > Precision::Confusion()) {
Base::Console().Warning("Transformed shape does not intersect original %s: Removed\n", (*o)->getNameInDocument()); Base::Console().Warning("Transformed shape does not intersect support %s: Removed\n", (*o)->getNameInDocument());
// Note: The removal happens in getSolid() after the fuse. If we remove here, // Note: The removal happens in getSolid() after the fuse. If we remove here,
// the histories get messed up and we get a crash // the histories get messed up and we get a crash
} }
@ -231,8 +235,14 @@ App::DocumentObjectExecReturn *Transformed::execute(void)
result = this->getSolid(mkFuse.Shape()); result = this->getSolid(mkFuse.Shape());
// lets check if the result is a solid // lets check if the result is a solid
if (result.IsNull()) if (result.IsNull())
return new App::DocumentObjectExecReturn("Transformed: Resulting shape is not a solid", *o); return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *o);
// check if mkFuse created more than one solids
TopExp_Explorer xp;
xp.Init(mkFuse.Shape(),TopAbs_SOLID);
if (xp.More())
xp.Next();
if (!xp.More()) // There are no rejected transformations even
rejected.clear(); // if the bb check guessed that there would be
} else { } else {
BRepAlgoAPI_Cut mkCut(support, transformedShapes); BRepAlgoAPI_Cut mkCut(support, transformedShapes);
if (!mkCut.IsDone()) if (!mkCut.IsDone())

View File

@ -45,11 +45,12 @@ public:
Transformed(); Transformed();
/** The shapes to be transformed /** The shapes to be transformed
if Originals is empty the instance is just a container for storing transformation data */ * if Originals is empty the instance is just a container for storing transformation data
*/
App::PropertyLinkList Originals; App::PropertyLinkList Originals;
/// Return first original, which serves as "Support" until Body feature becomes functional /// Return first original, which serves as "Support" until Body feature becomes functional
App::DocumentObject* getOriginalObject() const; App::DocumentObject* getSupportObject() const;
/// Get the list of transformations describing the members of the pattern /// Get the list of transformations describing the members of the pattern
// Note: Only the Scaled feature requires the originals // Note: Only the Scaled feature requires the originals
@ -72,11 +73,13 @@ public:
void positionBySupport(void); void positionBySupport(void);
/** returns a list of the transformations that where rejected during the last execute
* because they did not ovelap with the support
*/
const std::list<gp_Trsf> getRejectedTransformations(void) { return rejected; }
protected: protected:
void buildTransformHistory(BRepBuilderAPI_MakeShape& mkFuse, std::list<gp_Trsf> rejected;
const TopoDS_Shape& newShape,
const TopoDS_Shape& oldShape,
const int index);
}; };
} //namespace PartDesign } //namespace PartDesign

View File

@ -41,7 +41,7 @@
#include "ViewProviderMirrored.h" #include "ViewProviderMirrored.h"
#include "ViewProviderLinearPattern.h" #include "ViewProviderLinearPattern.h"
#include "ViewProviderPolarPattern.h" #include "ViewProviderPolarPattern.h"
//#include "ViewProviderScaled.h" #include "ViewProviderScaled.h"
#include "ViewProviderMultiTransform.h" #include "ViewProviderMultiTransform.h"
//#include "resources/qrc_PartDesign.cpp" //#include "resources/qrc_PartDesign.cpp"
@ -95,7 +95,7 @@ void PartDesignGuiExport initPartDesignGui()
PartDesignGui::ViewProviderMirrored ::init(); PartDesignGui::ViewProviderMirrored ::init();
PartDesignGui::ViewProviderLinearPattern ::init(); PartDesignGui::ViewProviderLinearPattern ::init();
PartDesignGui::ViewProviderPolarPattern ::init(); PartDesignGui::ViewProviderPolarPattern ::init();
// PartDesignGui::ViewProviderScaled ::init(); PartDesignGui::ViewProviderScaled ::init();
PartDesignGui::ViewProviderMultiTransform::init(); PartDesignGui::ViewProviderMultiTransform::init();
// add resources and reloads the translators // add resources and reloads the translators

View File

@ -25,6 +25,7 @@ set(PartDesignGui_LIBS
) )
set(PartDesignGui_MOC_HDRS set(PartDesignGui_MOC_HDRS
FeaturePickDialog.h
TaskPadParameters.h TaskPadParameters.h
TaskPocketParameters.h TaskPocketParameters.h
TaskChamferParameters.h TaskChamferParameters.h
@ -32,6 +33,7 @@ set(PartDesignGui_MOC_HDRS
TaskHoleParameters.h TaskHoleParameters.h
TaskRevolutionParameters.h TaskRevolutionParameters.h
TaskGrooveParameters.h TaskGrooveParameters.h
TaskTransformedMessages.h
TaskTransformedParameters.h TaskTransformedParameters.h
TaskMirroredParameters.h TaskMirroredParameters.h
TaskLinearPatternParameters.h TaskLinearPatternParameters.h
@ -45,6 +47,7 @@ SOURCE_GROUP("Moc" FILES ${PartDesignGui_MOC_SRCS})
qt4_add_resources(PartDesignGui_SRCS Resources/PartDesign.qrc) qt4_add_resources(PartDesignGui_SRCS Resources/PartDesign.qrc)
set(PartDesignGui_UIC_SRCS set(PartDesignGui_UIC_SRCS
FeaturePickDialog.ui
TaskPadParameters.ui TaskPadParameters.ui
TaskPocketParameters.ui TaskPocketParameters.ui
TaskChamferParameters.ui TaskChamferParameters.ui
@ -52,6 +55,7 @@ set(PartDesignGui_UIC_SRCS
TaskHoleParameters.ui TaskHoleParameters.ui
TaskRevolutionParameters.ui TaskRevolutionParameters.ui
TaskGrooveParameters.ui TaskGrooveParameters.ui
TaskTransformedMessages.ui
TaskMirroredParameters.ui TaskMirroredParameters.ui
TaskLinearPatternParameters.ui TaskLinearPatternParameters.ui
TaskPolarPatternParameters.ui TaskPolarPatternParameters.ui
@ -93,6 +97,9 @@ SET(PartDesignGuiViewProvider_SRCS
SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS}) SOURCE_GROUP("ViewProvider" FILES ${PartDesignGuiViewProvider_SRCS})
SET(PartDesignGuiTaskDlgs_SRCS SET(PartDesignGuiTaskDlgs_SRCS
FeaturePickDialog.ui
FeaturePickDialog.cpp
FeaturePickDialog.h
TaskPadParameters.ui TaskPadParameters.ui
TaskPadParameters.cpp TaskPadParameters.cpp
TaskPadParameters.h TaskPadParameters.h
@ -111,8 +118,11 @@ SET(PartDesignGuiTaskDlgs_SRCS
TaskGrooveParameters.ui TaskGrooveParameters.ui
TaskGrooveParameters.cpp TaskGrooveParameters.cpp
TaskGrooveParameters.h TaskGrooveParameters.h
TaskTransformedParameters.h TaskTransformedMessages.ui
TaskTransformedMessages.cpp
TaskTransformedMessages.h
TaskTransformedParameters.cpp TaskTransformedParameters.cpp
TaskTransformedParameters.h
TaskMirroredParameters.ui TaskMirroredParameters.ui
TaskMirroredParameters.cpp TaskMirroredParameters.cpp
TaskMirroredParameters.h TaskMirroredParameters.h

View File

@ -52,6 +52,8 @@
using namespace std; using namespace std;
#include "FeaturePickDialog.h"
//=========================================================================== //===========================================================================
// Part_Pad // Part_Pad
//=========================================================================== //===========================================================================
@ -717,23 +719,36 @@ CmdPartDesignMirrored::CmdPartDesignMirrored()
void CmdPartDesignMirrored::activated(int iMsg) void CmdPartDesignMirrored::activated(int iMsg)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + // Get a valid original from the user
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId()); // First check selections
if (n < 1) { std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
QObject::tr("Select one or more additive/subtractive features, please.")); features.insert(features.end(), subtractive.begin(), subtractive.end());
return; // Next create a list of all eligible objects
} if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("Mirrored"); std::string FeatName = getUniqueObjectName("Mirrored");
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::stringstream str; std::stringstream str;
std::vector<std::string> tempSelNames; std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = ["; str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << it->FeatName << ","; str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back(it->FeatName); tempSelNames.push_back((*it)->getNameInDocument());
} }
str << "]"; str << "]";
@ -756,9 +771,7 @@ void CmdPartDesignMirrored::activated(int iMsg)
bool CmdPartDesignMirrored::isActive(void) bool CmdPartDesignMirrored::isActive(void)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + return hasActiveDocument();
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId());
return n >= 1;
} }
//=========================================================================== //===========================================================================
@ -780,23 +793,36 @@ CmdPartDesignLinearPattern::CmdPartDesignLinearPattern()
void CmdPartDesignLinearPattern::activated(int iMsg) void CmdPartDesignLinearPattern::activated(int iMsg)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + // Get a valid original from the user
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId()); // First check selections
if (n < 1) { std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
QObject::tr("Select one or more additive/subtractive features, please.")); features.insert(features.end(), subtractive.begin(), subtractive.end());
return; // Next create a list of all eligible objects
} if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("LinearPattern"); std::string FeatName = getUniqueObjectName("LinearPattern");
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::stringstream str; std::stringstream str;
std::vector<std::string> tempSelNames; std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = ["; str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << it->FeatName << ","; str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back(it->FeatName); tempSelNames.push_back((*it)->getNameInDocument());
} }
str << "]"; str << "]";
@ -819,9 +845,7 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
bool CmdPartDesignLinearPattern::isActive(void) bool CmdPartDesignLinearPattern::isActive(void)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + return hasActiveDocument();
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId());
return n >= 1;
} }
//=========================================================================== //===========================================================================
@ -843,23 +867,36 @@ CmdPartDesignPolarPattern::CmdPartDesignPolarPattern()
void CmdPartDesignPolarPattern::activated(int iMsg) void CmdPartDesignPolarPattern::activated(int iMsg)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + // Get a valid original from the user
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId()); // First check selections
if (n < 1) { std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
QObject::tr("Select one or more additive/subtractive features, please.")); features.insert(features.end(), subtractive.begin(), subtractive.end());
return; // Next create a list of all eligible objects
} if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("PolarPattern"); std::string FeatName = getUniqueObjectName("PolarPattern");
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::stringstream str; std::stringstream str;
std::vector<std::string> tempSelNames; std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = ["; str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << it->FeatName << ","; str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back(it->FeatName); tempSelNames.push_back((*it)->getNameInDocument());
} }
str << "]"; str << "]";
@ -882,9 +919,7 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
bool CmdPartDesignPolarPattern::isActive(void) bool CmdPartDesignPolarPattern::isActive(void)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + return hasActiveDocument();
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId());
return n >= 1;
} }
//=========================================================================== //===========================================================================
@ -906,23 +941,36 @@ CmdPartDesignScaled::CmdPartDesignScaled()
void CmdPartDesignScaled::activated(int iMsg) void CmdPartDesignScaled::activated(int iMsg)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + // Get a valid original from the user
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId()); // First check selections
if (n < 1) { std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
QObject::tr("Select one or more additive/subtractive features, please.")); features.insert(features.end(), subtractive.begin(), subtractive.end());
return; // Next create a list of all eligible objects
} if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("Scaled"); std::string FeatName = getUniqueObjectName("Scaled");
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::stringstream str; std::stringstream str;
std::vector<std::string> tempSelNames; std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = ["; str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << it->FeatName << ","; str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back(it->FeatName); tempSelNames.push_back((*it)->getNameInDocument());
} }
str << "]"; str << "]";
@ -944,9 +992,7 @@ void CmdPartDesignScaled::activated(int iMsg)
bool CmdPartDesignScaled::isActive(void) bool CmdPartDesignScaled::isActive(void)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + return hasActiveDocument();
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId());
return n >= 1;
} }
//=========================================================================== //===========================================================================
@ -968,23 +1014,36 @@ CmdPartDesignMultiTransform::CmdPartDesignMultiTransform()
void CmdPartDesignMultiTransform::activated(int iMsg) void CmdPartDesignMultiTransform::activated(int iMsg)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + // Get a valid original from the user
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId()); // First check selections
if (n < 1) { std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
QObject::tr("Select one or more additive/subtractive features, please.")); features.insert(features.end(), subtractive.begin(), subtractive.end());
return; // Next create a list of all eligible objects
} if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("MultiTransform"); std::string FeatName = getUniqueObjectName("MultiTransform");
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::stringstream str; std::stringstream str;
std::vector<std::string> tempSelNames; std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = ["; str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<Gui::SelectionSingleton::SelObj>::iterator it = Sel.begin(); it != Sel.end(); ++it){ for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << it->FeatName << ","; str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back(it->FeatName); tempSelNames.push_back((*it)->getNameInDocument());
} }
str << "]"; str << "]";
@ -1002,9 +1061,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg)
bool CmdPartDesignMultiTransform::isActive(void) bool CmdPartDesignMultiTransform::isActive(void)
{ {
unsigned n = getSelection().countObjectsOfType(PartDesign::Additive::getClassTypeId()) + return hasActiveDocument();
getSelection().countObjectsOfType(PartDesign::Subtractive::getClassTypeId());
return n >= 1;
} }

View File

@ -0,0 +1,75 @@
/******************************************************************************
* Copyright (c)2012 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 <QPixmap>
# include <QDialog>
# include <QListIterator>
#endif
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/MainWindow.h>
#include <App/Document.h>
#include <Base/Tools.h>
#include "ui_FeaturePickDialog.h"
#include "FeaturePickDialog.h"
using namespace PartDesignGui;
FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects)
: QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog)
{
ui->setupUi(this);
for (std::vector<App::DocumentObject*>::const_iterator o = objects.begin(); o != objects.end(); o++)
ui->listWidget->addItem(QString::fromAscii((*o)->getNameInDocument()));
}
FeaturePickDialog::~FeaturePickDialog()
{
}
std::vector<App::DocumentObject*> FeaturePickDialog::getFeatures() {
std::vector<App::DocumentObject*> result;
for (std::vector<QString>::const_iterator s = features.begin(); s != features.end(); s++)
result.push_back(App::GetApplication().getActiveDocument()->getObject(s->toAscii().data()));
return result;
}
void FeaturePickDialog::accept()
{
features.clear();
QListIterator<QListWidgetItem*> i(ui->listWidget->selectedItems());
while (i.hasNext())
features.push_back(i.next()->text());
QDialog::accept();
}
#include "moc_FeaturePickDialog.cpp"

View File

@ -0,0 +1,55 @@
/******************************************************************************
* Copyright (c)2012 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 PARTDESIGNGUI_FeaturePickDialog_H
#define PARTDESIGNGUI_FeaturePickDialog_H
#include <QDialog>
#include <QString>
#include <App/DocumentObject.h>
namespace PartDesignGui {
class Ui_FeaturePickDialog;
class FeaturePickDialog : public QDialog
{
Q_OBJECT
public:
FeaturePickDialog(std::vector<App::DocumentObject*> &objects);
~FeaturePickDialog();
std::vector<App::DocumentObject*> getFeatures();
void accept();
protected Q_SLOTS:
private:
Ui_FeaturePickDialog* ui;
std::vector<QString> features;
};
}
#endif // PARTDESIGNGUI_FeaturePickDialog_H

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartDesignGui::FeaturePickDialog</class>
<widget class="QDialog" name="PartDesignGui::FeaturePickDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>Choose feature</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PartDesignGui::FeaturePickDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PartDesignGui::FeaturePickDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -29,6 +29,7 @@
#include "ui_TaskLinearPatternParameters.h" #include "ui_TaskLinearPatternParameters.h"
#include "TaskLinearPatternParameters.h" #include "TaskLinearPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h> #include <App/Application.h>
#include <App/Document.h> #include <App/Document.h>
#include <Gui/Application.h> #include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h> #include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureLinearPattern.h> #include <Mod/PartDesign/App/FeatureLinearPattern.h>
#include <Mod/Sketcher/App/SketchObject.h> #include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui; using namespace PartDesignGui;
using namespace Gui; using namespace Gui;
@ -62,7 +62,9 @@ TaskLinearPatternParameters::TaskLinearPatternParameters(ViewProviderTransformed
ui->buttonOK->hide(); ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true); ui->checkBoxUpdateView->setEnabled(true);
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -79,10 +81,13 @@ TaskLinearPatternParameters::TaskLinearPatternParameters(TaskMultiTransformParam
layout->addWidget(proxy); layout->addWidget(proxy);
ui->buttonOK->setEnabled(true); ui->buttonOK->setEnabled(true);
ui->listFeatures->hide(); ui->labelOriginal->hide();
ui->lineOriginal->hide();
ui->checkBoxUpdateView->hide(); ui->checkBoxUpdateView->hide();
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -100,35 +105,24 @@ void TaskLinearPatternParameters::setupUI()
this, SLOT(onLength(double))); this, SLOT(onLength(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(int)), connect(ui->spinOccurrences, SIGNAL(valueChanged(int)),
this, SLOT(onOccurrences(int))); this, SLOT(onOccurrences(int)));
connect(ui->buttonReference, SIGNAL(pressed()), connect(ui->buttonReference, SIGNAL(toggled(bool)),
this, SLOT(onButtonReference())); this, SLOT(onButtonReference(bool)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool))); this, SLOT(onUpdateView(bool)));
// TODO: The following code could be generic in TaskTransformedParameters
// if it were possible to make ui_TaskLinearPatternParameters a subclass of
// ui_TaskTransformedParameters
// ---------------------
// Add a context menu to the listview of the originals to delete items
QAction* action = new QAction(tr("Delete"), ui->listFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onOriginalDeleted()));
ui->listFeatures->addAction(action);
ui->listFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Get the feature data // Get the feature data
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::vector<App::DocumentObject*> originals = pcLinearPattern->Originals.getValues(); std::vector<App::DocumentObject*> originals = pcLinearPattern->Originals.getValues();
// Fill data into dialog elements // Fill data into dialog elements
ui->listFeatures->setEnabled(true); ui->lineOriginal->setEnabled(false);
ui->listFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++) for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{ {
if ((*i) != NULL) if ((*i) != NULL) { // find the first valid original
ui->listFeatures->addItem(QString::fromAscii((*i)->getNameInDocument())); ui->lineOriginal->setText(QString::fromAscii((*i)->getNameInDocument()));
break;
}
} }
QMetaObject::invokeMethod(ui->listFeatures, "setFocus", Qt::QueuedConnection);
// --------------------- // ---------------------
ui->buttonX->setEnabled(true); ui->buttonX->setEnabled(true);
@ -144,8 +138,10 @@ void TaskLinearPatternParameters::setupUI()
void TaskLinearPatternParameters::updateUI() void TaskLinearPatternParameters::updateUI()
{ {
if (updateUIinProgress) return; if (blockUpdate)
updateUIinProgress = true; return;
blockUpdate = true;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
App::DocumentObject* directionFeature = pcLinearPattern->Direction.getValue(); App::DocumentObject* directionFeature = pcLinearPattern->Direction.getValue();
@ -155,9 +151,9 @@ void TaskLinearPatternParameters::updateUI()
double length = pcLinearPattern->Length.getValue(); double length = pcLinearPattern->Length.getValue();
unsigned occurrences = pcLinearPattern->Occurrences.getValue(); unsigned occurrences = pcLinearPattern->Occurrences.getValue();
if ((featureSelectionMode || insideMultiTransform) && !stdDirection.empty()) ui->buttonReference->setChecked(referenceSelectionMode);
if (!stdDirection.empty())
{ {
ui->buttonReference->setDown(false);
ui->buttonX->setAutoExclusive(true); ui->buttonX->setAutoExclusive(true);
ui->buttonY->setAutoExclusive(true); ui->buttonY->setAutoExclusive(true);
ui->buttonZ->setAutoExclusive(true); ui->buttonZ->setAutoExclusive(true);
@ -165,80 +161,65 @@ void TaskLinearPatternParameters::updateUI()
ui->buttonY->setChecked(stdDirection == "Y"); ui->buttonY->setChecked(stdDirection == "Y");
ui->buttonZ->setChecked(stdDirection == "Z"); ui->buttonZ->setChecked(stdDirection == "Z");
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} else if ((directionFeature != NULL) && !directions.empty()) { } else if (directionFeature != NULL && !directions.empty()) {
ui->buttonX->setAutoExclusive(false); ui->buttonX->setAutoExclusive(false);
ui->buttonY->setAutoExclusive(false); ui->buttonY->setAutoExclusive(false);
ui->buttonZ->setAutoExclusive(false); ui->buttonZ->setAutoExclusive(false);
ui->buttonX->setChecked(false); ui->buttonX->setChecked(false);
ui->buttonY->setChecked(false); ui->buttonY->setChecked(false);
ui->buttonZ->setChecked(false); ui->buttonZ->setChecked(false);
ui->buttonReference->setDown(!featureSelectionMode);
ui->lineReference->setText(QString::fromAscii(directions.front().c_str())); ui->lineReference->setText(QString::fromAscii(directions.front().c_str()));
} else { } else {
// Error message? // Error message?
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} }
if (referenceSelectionMode)
ui->lineReference->setText(tr("Select an edge or a face"));
// Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we // Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we
// didn't check for updateUIinProgress // didn't check for blockUpdate
ui->checkReverse->setChecked(reverse); ui->checkReverse->setChecked(reverse);
ui->spinLength->setValue(length); ui->spinLength->setValue(length);
ui->spinOccurrences->setValue(occurrences); ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false; blockUpdate = false;
} }
void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); if (msg.Type == Gui::SelectionChanges::AddSelection) {
App::DocumentObject* selectedObject = pcLinearPattern->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (featureSelectionMode) { if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
if (originalSelected(msg))
ui->listFeatures->addItem(QString::fromAscii(selectedObject->getNameInDocument()));
} else {
if (!msg.pSubName || msg.pSubName[0] == '\0')
return; return;
std::string element(msg.pSubName); std::string subName(msg.pSubName);
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
((subName.size() > 4 && subName.substr(0,4) == "Edge") ||
(subName.size() > 4 && subName.substr(0,4) == "Face"))) {
if (msg.Type == Gui::SelectionChanges::AddSelection) { if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
// TODO return;
// if (originalElementName == "") {
// Base::Console().Error("Element created by this pattern cannot be used for direction\n");
// return;
// }
std::vector<std::string> directions; exitSelectionMode();
directions.push_back(element.c_str()); if (!blockUpdate) {
pcLinearPattern->Direction.setValue(getOriginalObject(), directions); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::vector<std::string> directions(1,subName);
pcLinearPattern->Direction.setValue(getSupportObject(), directions);
pcLinearPattern->StdDirection.setValue("");
if (insideMultiTransform) { recomputeFeature();
if (parentTask->updateView()) updateUI();
recomputeFeature(); }
} else else {
if (ui->checkBoxUpdateView->isChecked()) ui->buttonReference->setChecked(referenceSelectionMode);
recomputeFeature(); ui->lineReference->setText(QString::fromAscii(subName.c_str()));
}
if (!insideMultiTransform)
featureSelectionMode = true; // Jump back to selection of originals
showObject();
hideOriginals();
updateUI();
} }
} }
} }
void TaskLinearPatternParameters::onOriginalDeleted()
{
int row = ui->listFeatures->currentIndex().row();
TaskTransformedParameters::onOriginalDeleted(row);
ui->listFeatures->model()->removeRow(row);
}
void TaskLinearPatternParameters::onButtonX() { void TaskLinearPatternParameters::onButtonX() {
onStdDirection("X"); onStdDirection("X");
} }
@ -252,118 +233,124 @@ void TaskLinearPatternParameters::onButtonZ() {
} }
void TaskLinearPatternParameters::onCheckReverse(const bool on) { void TaskLinearPatternParameters::onCheckReverse(const bool on) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Reversed.setValue(on); pcLinearPattern->Reversed.setValue(on);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskLinearPatternParameters::onLength(const double l) { void TaskLinearPatternParameters::onLength(const double l) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Length.setValue(l); pcLinearPattern->Length.setValue(l);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskLinearPatternParameters::onOccurrences(const int n) { void TaskLinearPatternParameters::onOccurrences(const int n) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Occurrences.setValue(n); pcLinearPattern->Occurrences.setValue(n);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskLinearPatternParameters::onStdDirection(const std::string& dir) { void TaskLinearPatternParameters::onStdDirection(const std::string& dir) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->StdDirection.setValue(dir.c_str()); pcLinearPattern->StdDirection.setValue(dir.c_str());
pcLinearPattern->Direction.setValue(NULL); pcLinearPattern->Direction.setValue(NULL);
if (!insideMultiTransform)
featureSelectionMode = true; exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskLinearPatternParameters::onButtonReference() void TaskLinearPatternParameters::onButtonReference(bool checked)
{ {
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); if (checked ) {
pcLinearPattern->StdDirection.setValue(""); hideObject();
featureSelectionMode = false; showOriginals();
hideObject(); referenceSelectionMode = true;
showOriginals(); Gui::Selection().clearSelection();
addReferenceSelectionGate(true, true);
} else {
exitSelectionMode();
}
updateUI(); updateUI();
} }
void TaskLinearPatternParameters::onUpdateView(bool on) void TaskLinearPatternParameters::onUpdateView(bool on)
{ {
ui->buttonX->blockSignals(!on); blockUpdate = !on;
ui->buttonY->blockSignals(!on); if (on) {
ui->buttonZ->blockSignals(!on); // Do the same like in TaskDlgLinearPatternParameters::accept() but without doCommand
ui->listFeatures->blockSignals(!on); PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
ui->checkReverse->blockSignals(!on);
ui->spinLength->blockSignals(!on); std::string direction = getDirection();
ui->spinOccurrences->blockSignals(!on); if (!direction.empty()) {
std::vector<std::string> directions(1,direction);
pcLinearPattern->Direction.setValue(getSupportObject(), directions);
} else
pcLinearPattern->Direction.setValue(NULL);
std::string stdDirection = getStdDirection();
if (!stdDirection.empty())
pcLinearPattern->StdDirection.setValue(stdDirection.c_str());
else
pcLinearPattern->StdDirection.setValue(NULL);
pcLinearPattern->Reversed.setValue(getReverse());
pcLinearPattern->Length.setValue(getLength());
pcLinearPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
} }
const std::string TaskLinearPatternParameters::getStdDirection(void) const const std::string TaskLinearPatternParameters::getStdDirection(void) const
{ {
std::string stdDirection;
if (ui->buttonX->isChecked()) if (ui->buttonX->isChecked())
stdDirection = "X"; return std::string("X");
else if (ui->buttonY->isChecked()) else if (ui->buttonY->isChecked())
stdDirection = "Y"; return std::string("Y");
else if (ui->buttonZ->isChecked()) else if (ui->buttonZ->isChecked())
stdDirection = "Z"; return std::string("Z");
return std::string("");
if (!stdDirection.empty())
return std::string("\"") + stdDirection + "\"";
else
return std::string("");
} }
const QString TaskLinearPatternParameters::getDirection(void) const const std::string TaskLinearPatternParameters::getDirection(void) const
{ {
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject()); return ui->lineReference->text().toStdString();
App::DocumentObject* feature = pcLinearPattern->Direction.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> directions = pcLinearPattern->Direction.getSubValues();
QString buf;
if ((feature != NULL) && !directions.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(directions.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
} }
const bool TaskLinearPatternParameters::getReverse(void) const { const bool TaskLinearPatternParameters::getReverse(void) const
{
return ui->checkReverse->isChecked(); return ui->checkReverse->isChecked();
} }
const double TaskLinearPatternParameters::getLength(void) const { const double TaskLinearPatternParameters::getLength(void) const
{
return ui->spinLength->value(); return ui->spinLength->value();
} }
const unsigned TaskLinearPatternParameters::getOccurrences(void) const { const unsigned TaskLinearPatternParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value(); return ui->spinOccurrences->value();
} }
TaskLinearPatternParameters::~TaskLinearPatternParameters() TaskLinearPatternParameters::~TaskLinearPatternParameters()
{ {
delete ui; delete ui;
@ -404,12 +391,16 @@ bool TaskDlgLinearPatternParameters::accept()
return false; return false;
TaskLinearPatternParameters* linearpatternParameter = static_cast<TaskLinearPatternParameters*>(parameter); TaskLinearPatternParameters* linearpatternParameter = static_cast<TaskLinearPatternParameters*>(parameter);
std::string direction = linearpatternParameter->getDirection().toStdString(); std::string direction = linearpatternParameter->getDirection();
if (!direction.empty()) if (!direction.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), direction.c_str()); QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(linearpatternParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(direction.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str());
std::string stdDirection = linearpatternParameter->getStdDirection(); std::string stdDirection = linearpatternParameter->getStdDirection();
if (!stdDirection.empty()) Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdDirection = \"%s\"",name.c_str(),stdDirection.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdDirection = %s",name.c_str(),stdDirection.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),linearpatternParameter->getReverse()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),linearpatternParameter->getReverse());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),linearpatternParameter->getLength()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),linearpatternParameter->getLength());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),linearpatternParameter->getOccurrences()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),linearpatternParameter->getOccurrences());

View File

@ -41,7 +41,7 @@ namespace Gui {
class ViewProvider; class ViewProvider;
} }
namespace PartDesignGui { namespace PartDesignGui {
class TaskMultiTransformParameters; class TaskMultiTransformParameters;
@ -56,8 +56,8 @@ public:
TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout); TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskLinearPatternParameters(); virtual ~TaskLinearPatternParameters();
const QString getDirection(void) const;
const std::string getStdDirection(void) const; const std::string getStdDirection(void) const;
const std::string getDirection(void) const;
const bool getReverse(void) const; const bool getReverse(void) const;
const double getLength(void) const; const double getLength(void) const;
const unsigned getOccurrences(void) const; const unsigned getOccurrences(void) const;
@ -70,17 +70,16 @@ private Q_SLOTS:
void onCheckReverse(const bool on); void onCheckReverse(const bool on);
void onLength(const double l); void onLength(const double l);
void onOccurrences(const int n); void onOccurrences(const int n);
virtual void onButtonReference(); void onButtonReference(const bool checked);
virtual void onOriginalDeleted();
virtual void onUpdateView(bool); virtual void onUpdateView(bool);
protected: protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg); virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private: private:
void updateUI();
void setupUI(); void setupUI();
void updateUI();
private: private:
Ui_TaskLinearPatternParameters* ui; Ui_TaskLinearPatternParameters* ui;

View File

@ -15,7 +15,18 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QListWidget" name="listFeatures"/> <layout class="QHBoxLayout" name="horizontalLayoutOriginal">
<item>
<widget class="QLabel" name="labelOriginal">
<property name="text">
<string>Original feature</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineOriginal"/>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -52,6 +63,9 @@
<property name="text"> <property name="text">
<string>Direction</string> <string>Direction</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -132,6 +146,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -43,7 +43,6 @@
#include <Mod/PartDesign/App/FeatureMirrored.h> #include <Mod/PartDesign/App/FeatureMirrored.h>
#include <Mod/Sketcher/App/SketchObject.h> #include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui; using namespace PartDesignGui;
using namespace Gui; using namespace Gui;
@ -57,12 +56,15 @@ TaskMirroredParameters::TaskMirroredParameters(ViewProviderTransformed *Transfor
ui = new Ui_TaskMirroredParameters(); ui = new Ui_TaskMirroredParameters();
ui->setupUi(proxy); ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this); QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy); this->groupLayout()->addWidget(proxy);
ui->buttonOK->hide(); ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true); ui->checkBoxUpdateView->setEnabled(true);
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -79,10 +81,13 @@ TaskMirroredParameters::TaskMirroredParameters(TaskMultiTransformParameters *par
layout->addWidget(proxy); layout->addWidget(proxy);
ui->buttonOK->setEnabled(true); ui->buttonOK->setEnabled(true);
ui->listFeatures->hide(); ui->labelOriginal->hide();
ui->lineOriginal->hide();
ui->checkBoxUpdateView->hide(); ui->checkBoxUpdateView->hide();
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -94,35 +99,24 @@ void TaskMirroredParameters::setupUI()
this, SLOT(onButtonXZ())); this, SLOT(onButtonXZ()));
connect(ui->buttonYZ, SIGNAL(pressed()), connect(ui->buttonYZ, SIGNAL(pressed()),
this, SLOT(onButtonYZ())); this, SLOT(onButtonYZ()));
connect(ui->buttonReference, SIGNAL(pressed()), connect(ui->buttonReference, SIGNAL(toggled(bool)),
this, SLOT(onButtonReference())); this, SLOT(onButtonReference(bool)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool))); this, SLOT(onUpdateView(bool)));
// TODO: The following code could be generic in TaskTransformedParameters
// if it were possible to make ui_TaskMirroredParameters a subclass of
// ui_TaskTransformedParameters
// ---------------------
// Add a context menu to the listview of the originals to delete items
QAction* action = new QAction(tr("Delete"), ui->listFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onOriginalDeleted()));
ui->listFeatures->addAction(action);
ui->listFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Get the feature data // Get the feature data
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::vector<App::DocumentObject*> originals = pcMirrored->Originals.getValues(); std::vector<App::DocumentObject*> originals = pcMirrored->Originals.getValues();
// Fill data into dialog elements // Fill data into dialog elements
ui->listFeatures->setEnabled(true); ui->lineOriginal->setEnabled(false);
ui->listFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++) for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{ {
if ((*i) != NULL) if ((*i) != NULL) { // find the first valid original
ui->listFeatures->addItem(QString::fromAscii((*i)->getNameInDocument())); ui->lineOriginal->setText(QString::fromAscii((*i)->getNameInDocument()));
break;
}
} }
QMetaObject::invokeMethod(ui->listFeatures, "setFocus", Qt::QueuedConnection);
// --------------------- // ---------------------
ui->buttonXY->setEnabled(true); ui->buttonXY->setEnabled(true);
@ -130,22 +124,22 @@ void TaskMirroredParameters::setupUI()
ui->buttonYZ->setEnabled(true); ui->buttonYZ->setEnabled(true);
ui->buttonReference->setEnabled(true); ui->buttonReference->setEnabled(true);
ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only ui->lineReference->setEnabled(false); // This is never enabled since it is for optical feed-back only
updateUI(); updateUI();
} }
void TaskMirroredParameters::updateUI() void TaskMirroredParameters::updateUI()
{ {
if (updateUIinProgress) return; if (blockUpdate)
updateUIinProgress = true; return;
blockUpdate = true;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue(); App::DocumentObject* mirrorPlaneFeature = pcMirrored->MirrorPlane.getValue();
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues(); std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
std::string stdMirrorPlane = pcMirrored->StdMirrorPlane.getValue(); std::string stdMirrorPlane = pcMirrored->StdMirrorPlane.getValue();
if ((featureSelectionMode || insideMultiTransform) && !stdMirrorPlane.empty()) ui->buttonReference->setChecked(referenceSelectionMode);
if (!stdMirrorPlane.empty())
{ {
ui->buttonReference->setDown(false);
ui->buttonXY->setAutoExclusive(true); ui->buttonXY->setAutoExclusive(true);
ui->buttonXZ->setAutoExclusive(true); ui->buttonXZ->setAutoExclusive(true);
ui->buttonYZ->setAutoExclusive(true); ui->buttonYZ->setAutoExclusive(true);
@ -153,81 +147,67 @@ void TaskMirroredParameters::updateUI()
ui->buttonXZ->setChecked(stdMirrorPlane == "XZ"); ui->buttonXZ->setChecked(stdMirrorPlane == "XZ");
ui->buttonYZ->setChecked(stdMirrorPlane == "YZ"); ui->buttonYZ->setChecked(stdMirrorPlane == "YZ");
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} else if ((mirrorPlaneFeature != NULL) && !mirrorPlanes.empty()) { } else if (mirrorPlaneFeature != NULL && !mirrorPlanes.empty()) {
ui->buttonXY->setAutoExclusive(false); ui->buttonXY->setAutoExclusive(false);
ui->buttonXZ->setAutoExclusive(false); ui->buttonXZ->setAutoExclusive(false);
ui->buttonYZ->setAutoExclusive(false); ui->buttonYZ->setAutoExclusive(false);
ui->buttonXY->setChecked(false); ui->buttonXY->setChecked(false);
ui->buttonXZ->setChecked(false); ui->buttonXZ->setChecked(false);
ui->buttonYZ->setChecked(false); ui->buttonYZ->setChecked(false);
ui->buttonReference->setDown(!featureSelectionMode);
ui->lineReference->setText(QString::fromAscii(mirrorPlanes.front().c_str())); ui->lineReference->setText(QString::fromAscii(mirrorPlanes.front().c_str()));
} else { } else {
// Error message? // Error message?
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} }
if (referenceSelectionMode)
ui->lineReference->setText(tr("Select a plane"));
updateUIinProgress = false; blockUpdate = false;
} }
void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); if (msg.Type == Gui::SelectionChanges::AddSelection) {
App::DocumentObject* selectedObject = pcMirrored->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (featureSelectionMode) { if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
if (originalSelected(msg))
ui->listFeatures->addItem(QString::fromAscii(selectedObject->getNameInDocument()));
} else {
if (!msg.pSubName || msg.pSubName[0] == '\0')
return; return;
std::string element(msg.pSubName); std::string subName(msg.pSubName);
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
(subName.size() > 4 && subName.substr(0,4) == "Face")) {
if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
return;
if (element.substr(0,4) != "Face") exitSelectionMode();
return; if (!blockUpdate) {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::vector<std::string> mirrorPlanes(1,subName);
pcMirrored->MirrorPlane.setValue(getSupportObject(), mirrorPlanes);
pcMirrored->StdMirrorPlane.setValue("");
if (msg.Type == Gui::SelectionChanges::AddSelection) { recomputeFeature();
std::vector<std::string> mirrorPlanes; updateUI();
mirrorPlanes.push_back(element.c_str()); }
pcMirrored->MirrorPlane.setValue(getOriginalObject(), mirrorPlanes); else {
ui->buttonReference->setChecked(referenceSelectionMode);
if (insideMultiTransform) { ui->lineReference->setText(QString::fromAscii(subName.c_str()));
if (parentTask->updateView()) }
recomputeFeature();
} else
if (ui->checkBoxUpdateView->isChecked())
recomputeFeature();
if (!insideMultiTransform)
featureSelectionMode = true; // Jump back to selection of originals
showObject();
hideOriginals();
updateUI();
} }
} }
} }
void TaskMirroredParameters::onOriginalDeleted()
{
int row = ui->listFeatures->currentIndex().row();
TaskTransformedParameters::onOriginalDeleted(row);
ui->listFeatures->model()->removeRow(row);
}
void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) { void TaskMirroredParameters::onStdMirrorPlane(const std::string &plane) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
pcMirrored->StdMirrorPlane.setValue(plane.c_str()); pcMirrored->StdMirrorPlane.setValue(plane.c_str());
pcMirrored->MirrorPlane.setValue(NULL); pcMirrored->MirrorPlane.setValue(NULL);
if (!insideMultiTransform)
featureSelectionMode = true; exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
@ -243,61 +223,61 @@ void TaskMirroredParameters::onButtonYZ() {
onStdMirrorPlane("YZ"); onStdMirrorPlane("YZ");
} }
void TaskMirroredParameters::onButtonReference() void TaskMirroredParameters::onButtonReference(bool checked)
{ {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); if (checked ) {
pcMirrored->StdMirrorPlane.setValue(""); hideObject();
featureSelectionMode = false; showOriginals();
hideObject(); referenceSelectionMode = true;
showOriginals(); Gui::Selection().clearSelection();
addReferenceSelectionGate(false, true);
} else {
exitSelectionMode();
}
updateUI(); updateUI();
} }
void TaskMirroredParameters::onUpdateView(bool on) void TaskMirroredParameters::onUpdateView(bool on)
{ {
ui->buttonXY->blockSignals(!on); blockUpdate = !on;
ui->buttonYZ->blockSignals(!on); if (on) {
ui->buttonXZ->blockSignals(!on); // Do the same like in TaskDlgMirroredParameters::accept() but without doCommand
ui->listFeatures->blockSignals(!on); PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::string mirrorPlane = getMirrorPlane();
if (!mirrorPlane.empty()) {
std::vector<std::string> planes(1,mirrorPlane);
pcMirrored->MirrorPlane.setValue(getSupportObject(),planes);
} else
pcMirrored->MirrorPlane.setValue(NULL);
std::string stdMirrorPlane = getStdMirrorPlane();
if (!stdMirrorPlane.empty())
pcMirrored->StdMirrorPlane.setValue(stdMirrorPlane.c_str());
else
pcMirrored->StdMirrorPlane.setValue(NULL);
recomputeFeature();
}
} }
const std::string TaskMirroredParameters::getStdMirrorPlane(void) const const std::string TaskMirroredParameters::getStdMirrorPlane(void) const
{ {
std::string stdMirrorPlane;
if (ui->buttonXY->isChecked()) if (ui->buttonXY->isChecked())
stdMirrorPlane = "XY"; return std::string("XY");
else if (ui->buttonYZ->isChecked()) else if (ui->buttonYZ->isChecked())
stdMirrorPlane = "YZ"; return std::string("YZ");
else if (ui->buttonXZ->isChecked()) else if (ui->buttonXZ->isChecked())
stdMirrorPlane = "XZ"; return std::string("XZ");
return std::string("");
if (!stdMirrorPlane.empty())
return std::string("\"") + stdMirrorPlane + "\"";
else
return std::string("");
} }
const QString TaskMirroredParameters::getMirrorPlane(void) const const std::string TaskMirroredParameters::getMirrorPlane(void) const
{ {
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject()); return ui->lineReference->text().toStdString();
App::DocumentObject* feature = pcMirrored->MirrorPlane.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> mirrorPlanes = pcMirrored->MirrorPlane.getSubValues();
QString buf;
if ((feature != NULL) && !mirrorPlanes.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(mirrorPlanes.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
} }
TaskMirroredParameters::~TaskMirroredParameters() TaskMirroredParameters::~TaskMirroredParameters()
{ {
delete ui; delete ui;
@ -338,12 +318,16 @@ bool TaskDlgMirroredParameters::accept()
return false; return false;
TaskMirroredParameters* mirrorParameter = static_cast<TaskMirroredParameters*>(parameter); TaskMirroredParameters* mirrorParameter = static_cast<TaskMirroredParameters*>(parameter);
std::string mirrorPlane = mirrorParameter->getMirrorPlane().toStdString(); std::string mirrorPlane = mirrorParameter->getMirrorPlane();
if (!mirrorPlane.empty()) if (!mirrorPlane.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str()); QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(mirrorParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(mirrorPlane.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str());
std::string stdMirrorPlane = mirrorParameter->getStdMirrorPlane(); std::string stdMirrorPlane = mirrorParameter->getStdMirrorPlane();
if (!stdMirrorPlane.empty()) Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdMirrorPlane = \"%s\"",name.c_str(),stdMirrorPlane.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdMirrorPlane = %s",name.c_str(),stdMirrorPlane.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid()) if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString()); throw Base::Exception(TransformedView->getObject()->getStatusString());

View File

@ -41,7 +41,7 @@ namespace Gui {
class ViewProvider; class ViewProvider;
} }
namespace PartDesignGui { namespace PartDesignGui {
class TaskMultiTransformParameters; class TaskMultiTransformParameters;
@ -57,18 +57,17 @@ public:
virtual ~TaskMirroredParameters(); virtual ~TaskMirroredParameters();
const QString getMirrorPlane(void) const;
const std::string getStdMirrorPlane(void) const; const std::string getStdMirrorPlane(void) const;
const std::string getMirrorPlane(void) const;
private Q_SLOTS: private Q_SLOTS:
void onButtonXY(); void onButtonXY();
void onButtonXZ(); void onButtonXZ();
void onButtonYZ(); void onButtonYZ();
virtual void onButtonReference(); void onButtonReference(const bool checked);
virtual void onOriginalDeleted();
virtual void onUpdateView(bool); virtual void onUpdateView(bool);
protected: protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg); virtual void onSelectionChanged(const Gui::SelectionChanges& msg);

View File

@ -15,7 +15,18 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QListWidget" name="listFeatures"/> <layout class="QHBoxLayout" name="horizontalLayoutOriginal">
<item>
<widget class="QLabel" name="labelOriginal">
<property name="text">
<string>Original feature</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineOriginal"/>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
@ -52,6 +63,9 @@
<property name="text"> <property name="text">
<string>Plane</string> <string>Plane</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -80,6 +94,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -68,35 +68,35 @@ TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransform
this->groupLayout()->addWidget(proxy); this->groupLayout()->addWidget(proxy);
// Create a context menu for the listview of transformation features // Create a context menu for the listview of transformation features
QAction* action = new QAction(tr("Edit"), ui->listFeatures); QAction* action = new QAction(tr("Edit"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformEdit())); this, SLOT(onTransformEdit()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Delete"), ui->listFeatures); action = new QAction(tr("Delete"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformDelete())); this, SLOT(onTransformDelete()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add mirrored transformation"), ui->listFeatures); action = new QAction(tr("Add mirrored transformation"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddMirrored())); this, SLOT(onTransformAddMirrored()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add linear pattern"), ui->listFeatures); action = new QAction(tr("Add linear pattern"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddLinearPattern())); this, SLOT(onTransformAddLinearPattern()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add polar pattern"), ui->listFeatures); action = new QAction(tr("Add polar pattern"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddPolarPattern())); this, SLOT(onTransformAddPolarPattern()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add scaled transformation"), ui->listFeatures); action = new QAction(tr("Add scaled transformation"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddScaled())); this, SLOT(onTransformAddScaled()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Move up"), ui->listFeatures); action = new QAction(tr("Move up"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onMoveUp())); this, SLOT(onMoveUp()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Move down"), ui->listFeatures); action = new QAction(tr("Move down"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()), action->connect(action, SIGNAL(triggered()),
this, SLOT(onMoveDown())); this, SLOT(onMoveDown()));
ui->listTransformFeatures->addAction(action); ui->listTransformFeatures->addAction(action);
@ -127,51 +127,34 @@ TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransform
editHint = true; editHint = true;
} }
// TODO: The following code could be generic in TaskTransformedParameters
// if it were possible to make ui_TaskMultiTransformParameters a subclass of
// ui_TaskTransformedParameters
// ---------------------
// Add a context menu to the listview of the originals to delete items
action = new QAction(tr("Delete"), ui->listFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onOriginalDeleted()));
ui->listFeatures->addAction(action);
ui->listFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Get the Originals data // Get the Originals data
std::vector<App::DocumentObject*> originals = pcMultiTransform->Originals.getValues(); std::vector<App::DocumentObject*> originals = pcMultiTransform->Originals.getValues();
// Fill data into dialog elements // Fill data into dialog elements
ui->listFeatures->setEnabled(true); ui->lineOriginal->setEnabled(false); // This is never enabled since it is for optical feed-back only
ui->listFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++) for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{ {
if ((*i) != NULL) if ((*i) != NULL) { // find the first valid original
ui->listFeatures->addItem(QString::fromAscii((*i)->getNameInDocument())); ui->lineOriginal->setText(QString::fromAscii((*i)->getNameInDocument()));
break;
}
} }
QMetaObject::invokeMethod(ui->listFeatures, "setFocus", Qt::QueuedConnection);
// --------------------- // ---------------------
} }
void TaskMultiTransformParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskMultiTransformParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject()); if (originalSelected(msg)) {
App::DocumentObject* selectedObject = pcMultiTransform->getDocument()->getActiveObject(); App::DocumentObject* selectedObject = TransformedView->getObject()->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId())) ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
return;
if (featureSelectionMode) {
if (originalSelected(msg))
ui->listFeatures->addItem(QString::fromAscii(selectedObject->getNameInDocument()));
} else {
// There is no reference that could be selected... must be an error to arrive here at all!
featureSelectionMode = true;
} }
} }
void TaskMultiTransformParameters::closeSubTask() void TaskMultiTransformParameters::closeSubTask()
{ {
if (subTask) { if (subTask) {
exitSelectionMode();
disconnect(ui->checkBoxUpdateView, 0, subTask, 0);
delete subTask; delete subTask;
subTask = NULL; subTask = NULL;
} }
@ -184,14 +167,15 @@ void TaskMultiTransformParameters::onTransformDelete()
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject()); PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues(); std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
App::DocumentObject* feature = *(transformFeatures.begin() + row); App::DocumentObject* feature = transformFeatures[row];
pcMultiTransform->getDocument()->remObject(feature->getNameInDocument()); pcMultiTransform->getDocument()->remObject(feature->getNameInDocument());
closeSubTask(); closeSubTask();
transformFeatures.erase(transformFeatures.begin() + row); transformFeatures.erase(transformFeatures.begin() + row);
pcMultiTransform->Transformations.setValues(transformFeatures); pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked()) // Note: When the last transformation is deleted, recomputeFeature does nothing, because Transformed::execute()
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform); // says: "No transformations defined, exit silently"
recomputeFeature();
ui->listTransformFeatures->model()->removeRow(row); ui->listTransformFeatures->model()->removeRow(row);
ui->listTransformFeatures->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); ui->listTransformFeatures->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
@ -217,6 +201,9 @@ void TaskMultiTransformParameters::onTransformEdit()
subTask = new TaskScaledParameters(this, ui->verticalLayout); subTask = new TaskScaledParameters(this, ui->verticalLayout);
else else
return; // TODO: Show an error? return; // TODO: Show an error?
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
subTask, SLOT(onUpdateView(bool)));
} }
void TaskMultiTransformParameters::onTransformActivated(const QModelIndex& index) { void TaskMultiTransformParameters::onTransformActivated(const QModelIndex& index) {
@ -230,7 +217,7 @@ void TaskMultiTransformParameters::onTransformAddMirrored()
Gui::Command::openCommand("Mirrored"); Gui::Command::openCommand("Mirrored");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",newFeatName.c_str());
Gui::Command::updateActive(); //Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdMirrorPlane = \"XY\"", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdMirrorPlane = \"XY\"", newFeatName.c_str());
finishAdd(newFeatName); finishAdd(newFeatName);
@ -243,7 +230,7 @@ void TaskMultiTransformParameters::onTransformAddLinearPattern()
Gui::Command::openCommand("LinearPattern"); Gui::Command::openCommand("LinearPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",newFeatName.c_str());
Gui::Command::updateActive(); //Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdDirection = \"X\"", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdDirection = \"X\"", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Length = 100", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Length = 100", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
@ -258,7 +245,7 @@ void TaskMultiTransformParameters::onTransformAddPolarPattern()
Gui::Command::openCommand("PolarPattern"); Gui::Command::openCommand("PolarPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",newFeatName.c_str());
Gui::Command::updateActive(); //Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdAxis = \"X\"", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.StdAxis = \"X\"", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Angle = 360", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Angle = 360", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
@ -273,7 +260,7 @@ void TaskMultiTransformParameters::onTransformAddScaled()
Gui::Command::openCommand("Scaled"); Gui::Command::openCommand("Scaled");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Scaled\",\"%s\")",newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Scaled\",\"%s\")",newFeatName.c_str());
Gui::Command::updateActive(); //Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Factor = 2", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Factor = 2", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
@ -294,11 +281,12 @@ void TaskMultiTransformParameters::finishAdd(std::string &newFeatName)
int row = ui->listTransformFeatures->currentIndex().row(); int row = ui->listTransformFeatures->currentIndex().row();
if (row < 0) { if (row < 0) {
// Happens when first row (first transformation) is created // Happens when first row (first transformation) is created
row = 0;
// Hide all the originals now (hiding them in Command.cpp presents the user with an empty screen!) // Hide all the originals now (hiding them in Command.cpp presents the user with an empty screen!)
hideOriginals(); hideOriginals();
} }
// Insert new transformation after the selected row
// This means that in order to insert at the beginning, the user has to use "Move Up" in the menu
App::DocumentObject* newFeature = pcMultiTransform->getDocument()->getObject(newFeatName.c_str()); App::DocumentObject* newFeature = pcMultiTransform->getDocument()->getObject(newFeatName.c_str());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues(); std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
if (row == ui->listTransformFeatures->model()->rowCount() - 1) { if (row == ui->listTransformFeatures->model()->rowCount() - 1) {
@ -308,14 +296,14 @@ void TaskMultiTransformParameters::finishAdd(std::string &newFeatName)
ui->listTransformFeatures->addItem(QString::fromAscii(newFeature->Label.getValue())); ui->listTransformFeatures->addItem(QString::fromAscii(newFeature->Label.getValue()));
ui->listTransformFeatures->setCurrentRow(row+1, QItemSelectionModel::ClearAndSelect); ui->listTransformFeatures->setCurrentRow(row+1, QItemSelectionModel::ClearAndSelect);
} else { } else {
transformFeatures.insert(transformFeatures.begin() + row, newFeature); // Note: The feature tree always seems to append to the end, no matter what we say here
ui->listTransformFeatures->insertItem(row, QString::fromAscii(newFeature->Label.getValue())); transformFeatures.insert(transformFeatures.begin() + row + 1, newFeature);
ui->listTransformFeatures->setCurrentRow(row, QItemSelectionModel::ClearAndSelect); ui->listTransformFeatures->insertItem(row + 1, QString::fromAscii(newFeature->Label.getValue()));
ui->listTransformFeatures->setCurrentRow(row + 1, QItemSelectionModel::ClearAndSelect);
} }
pcMultiTransform->Transformations.setValues(transformFeatures); pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked()) recomputeFeature();
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
// Set state to hidden - only the MultiTransform should be visible // Set state to hidden - only the MultiTransform should be visible
Gui::Command::doCommand( Gui::Command::doCommand(
@ -331,7 +319,7 @@ void TaskMultiTransformParameters::moveTransformFeature(const int increment)
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject()); PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues(); std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
App::DocumentObject* feature = *(transformFeatures.begin() + row); App::DocumentObject* feature = transformFeatures[row];
transformFeatures.erase(transformFeatures.begin() + row); transformFeatures.erase(transformFeatures.begin() + row);
QListWidgetItem* item = new QListWidgetItem(*(ui->listTransformFeatures->item(row))); QListWidgetItem* item = new QListWidgetItem(*(ui->listTransformFeatures->item(row)));
ui->listTransformFeatures->model()->removeRow(row); ui->listTransformFeatures->model()->removeRow(row);
@ -355,8 +343,7 @@ void TaskMultiTransformParameters::moveTransformFeature(const int increment)
} }
pcMultiTransform->Transformations.setValues(transformFeatures); pcMultiTransform->Transformations.setValues(transformFeatures);
if (ui->checkBoxUpdateView->isChecked()) recomputeFeature();
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
} }
void TaskMultiTransformParameters::onMoveUp() void TaskMultiTransformParameters::onMoveUp()
@ -373,19 +360,13 @@ void TaskMultiTransformParameters::onSubTaskButtonOK() {
closeSubTask(); closeSubTask();
} }
void TaskMultiTransformParameters::onOriginalDeleted()
{
int row = ui->listFeatures->currentIndex().row();
TaskTransformedParameters::onOriginalDeleted(row);
ui->listFeatures->model()->removeRow(row);
}
void TaskMultiTransformParameters::onUpdateView(bool on) void TaskMultiTransformParameters::onUpdateView(bool on)
{ {
ui->listFeatures->blockSignals(!on); blockUpdate = !on;
if (on)
recomputeFeature();
} }
const std::vector<App::DocumentObject*> TaskMultiTransformParameters::getTransformFeatures(void) const const std::vector<App::DocumentObject*> TaskMultiTransformParameters::getTransformFeatures(void) const
{ {
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject()); PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
@ -408,16 +389,6 @@ void TaskMultiTransformParameters::changeEvent(QEvent *e)
} }
} }
void TaskMultiTransformParameters::recomputeFeature() {
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
pcMultiTransform->getDocument()->recomputeFeature(pcMultiTransform);
}
const bool TaskMultiTransformParameters::updateView() const
{
return ui->checkBoxUpdateView->isChecked();
}
//************************************************************************** //**************************************************************************
//************************************************************************** //**************************************************************************
// TaskDialog // TaskDialog

View File

@ -62,11 +62,6 @@ public:
/// Return the currently active subFeature /// Return the currently active subFeature
PartDesign::Transformed* getSubFeature(void) { return subFeature; } PartDesign::Transformed* getSubFeature(void) { return subFeature; }
/// Recompute the feature associated with this task
void recomputeFeature();
/// Tell the subtask whether the view should be updated
const bool updateView() const;
private Q_SLOTS: private Q_SLOTS:
void onTransformDelete(); void onTransformDelete();
void onTransformEdit(); void onTransformEdit();
@ -77,13 +72,11 @@ private Q_SLOTS:
void onTransformAddScaled(); void onTransformAddScaled();
void onMoveUp(); void onMoveUp();
void onMoveDown(); void onMoveDown();
virtual void onButtonReference() {}
virtual void onOriginalDeleted();
virtual void onUpdateView(bool);
/// User finished editing a subFeature /// User finished editing a subFeature
virtual void onSubTaskButtonOK(); virtual void onSubTaskButtonOK();
// Note: There is no Cancel button because I couldn't work out how to save the state of // Note: There is no Cancel button because I couldn't work out how to save the state of
// a subFeature so as to revert the changes of an edit operation // a subFeature so as to revert the changes of an edit operation
virtual void onUpdateView(bool);
protected: protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>225</width> <width>225</width>
<height>559</height> <height>182</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,14 +15,18 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="label_3"> <layout class="QHBoxLayout" name="horizontalLayoutOriginal">
<property name="text"> <item>
<string>Originals</string> <widget class="QLabel" name="labelOriginal">
</property> <property name="text">
</widget> <string>Original feature</string>
</item> </property>
<item> </widget>
<widget class="QListWidget" name="listFeatures"/> </item>
<item>
<widget class="QLineEdit" name="lineOriginal"/>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
@ -32,7 +36,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QListWidget" name="listTransformFeatures"/> <widget class="QListWidget" name="listTransformFeatures">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="checkBoxUpdateView"> <widget class="QCheckBox" name="checkBoxUpdateView">

View File

@ -29,6 +29,7 @@
#include "ui_TaskPolarPatternParameters.h" #include "ui_TaskPolarPatternParameters.h"
#include "TaskPolarPatternParameters.h" #include "TaskPolarPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h> #include <App/Application.h>
#include <App/Document.h> #include <App/Document.h>
#include <Gui/Application.h> #include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h> #include <Gui/Command.h>
#include <Mod/PartDesign/App/FeaturePolarPattern.h> #include <Mod/PartDesign/App/FeaturePolarPattern.h>
#include <Mod/Sketcher/App/SketchObject.h> #include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui; using namespace PartDesignGui;
using namespace Gui; using namespace Gui;
@ -62,7 +62,9 @@ TaskPolarPatternParameters::TaskPolarPatternParameters(ViewProviderTransformed *
ui->buttonOK->hide(); ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true); ui->checkBoxUpdateView->setEnabled(true);
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -79,10 +81,13 @@ TaskPolarPatternParameters::TaskPolarPatternParameters(TaskMultiTransformParamet
layout->addWidget(proxy); layout->addWidget(proxy);
ui->buttonOK->setEnabled(true); ui->buttonOK->setEnabled(true);
ui->listFeatures->hide(); ui->labelOriginal->hide();
ui->lineOriginal->hide();
ui->checkBoxUpdateView->hide(); ui->checkBoxUpdateView->hide();
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! referenceSelectionMode = false;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -100,35 +105,24 @@ void TaskPolarPatternParameters::setupUI()
this, SLOT(onAngle(double))); this, SLOT(onAngle(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(int)), connect(ui->spinOccurrences, SIGNAL(valueChanged(int)),
this, SLOT(onOccurrences(int))); this, SLOT(onOccurrences(int)));
connect(ui->buttonReference, SIGNAL(pressed()), connect(ui->buttonReference, SIGNAL(toggled(bool)),
this, SLOT(onButtonReference())); this, SLOT(onButtonReference(bool)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool))); this, SLOT(onUpdateView(bool)));
// TODO: The following code could be generic in TaskTransformedParameters
// if it were possible to make ui_TaskPolarPatternParameters a subclass of
// ui_TaskTransformedParameters
// ---------------------
// Add a context menu to the listview of the originals to delete items
QAction* action = new QAction(tr("Delete"), ui->listFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onOriginalDeleted()));
ui->listFeatures->addAction(action);
ui->listFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Get the feature data // Get the feature data
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
std::vector<App::DocumentObject*> originals = pcPolarPattern->Originals.getValues(); std::vector<App::DocumentObject*> originals = pcPolarPattern->Originals.getValues();
// Fill data into dialog elements // Fill data into dialog elements
ui->listFeatures->setEnabled(true); ui->lineOriginal->setEnabled(false);
ui->listFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++) for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{ {
if ((*i) != NULL) if ((*i) != NULL) { // find the first valid original
ui->listFeatures->addItem(QString::fromAscii((*i)->getNameInDocument())); ui->lineOriginal->setText(QString::fromAscii((*i)->getNameInDocument()));
break;
}
} }
QMetaObject::invokeMethod(ui->listFeatures, "setFocus", Qt::QueuedConnection);
// --------------------- // ---------------------
ui->buttonX->setEnabled(true); ui->buttonX->setEnabled(true);
@ -144,8 +138,9 @@ void TaskPolarPatternParameters::setupUI()
void TaskPolarPatternParameters::updateUI() void TaskPolarPatternParameters::updateUI()
{ {
if (updateUIinProgress) return; if (blockUpdate)
updateUIinProgress = true; return;
blockUpdate = true;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
@ -156,9 +151,9 @@ void TaskPolarPatternParameters::updateUI()
double angle = pcPolarPattern->Angle.getValue(); double angle = pcPolarPattern->Angle.getValue();
unsigned occurrences = pcPolarPattern->Occurrences.getValue(); unsigned occurrences = pcPolarPattern->Occurrences.getValue();
if ((featureSelectionMode || insideMultiTransform) && !stdAxis.empty()) ui->buttonReference->setChecked(referenceSelectionMode);
if (!stdAxis.empty())
{ {
ui->buttonReference->setDown(false);
ui->buttonX->setAutoExclusive(true); ui->buttonX->setAutoExclusive(true);
ui->buttonY->setAutoExclusive(true); ui->buttonY->setAutoExclusive(true);
ui->buttonZ->setAutoExclusive(true); ui->buttonZ->setAutoExclusive(true);
@ -166,82 +161,62 @@ void TaskPolarPatternParameters::updateUI()
ui->buttonY->setChecked(stdAxis == "Y"); ui->buttonY->setChecked(stdAxis == "Y");
ui->buttonZ->setChecked(stdAxis == "Z"); ui->buttonZ->setChecked(stdAxis == "Z");
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} else if ((axisFeature != NULL) && !axes.empty()) { } else if (axisFeature != NULL && !axes.empty()) {
ui->buttonX->setAutoExclusive(false); ui->buttonX->setAutoExclusive(false);
ui->buttonY->setAutoExclusive(false); ui->buttonY->setAutoExclusive(false);
ui->buttonZ->setAutoExclusive(false); ui->buttonZ->setAutoExclusive(false);
ui->buttonX->setChecked(false); ui->buttonX->setChecked(false);
ui->buttonY->setChecked(false); ui->buttonY->setChecked(false);
ui->buttonZ->setChecked(false); ui->buttonZ->setChecked(false);
ui->buttonReference->setDown(!featureSelectionMode);
ui->lineReference->setText(QString::fromAscii(axes.front().c_str())); ui->lineReference->setText(QString::fromAscii(axes.front().c_str()));
} else { } else {
// Error message? // Error message?
ui->lineReference->setText(tr("")); ui->lineReference->setText(tr(""));
} }
if (referenceSelectionMode)
ui->lineReference->setText(tr("Select an edge"));
ui->checkReverse->setChecked(reverse); ui->checkReverse->setChecked(reverse);
ui->spinAngle->setValue(angle); ui->spinAngle->setValue(angle);
ui->spinOccurrences->setValue(occurrences); ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false; blockUpdate = false;
} }
void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); if (msg.Type == Gui::SelectionChanges::AddSelection) {
App::DocumentObject* selectedObject = pcPolarPattern->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId()))
return;
if (featureSelectionMode) { if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
if (originalSelected(msg))
ui->listFeatures->addItem(QString::fromAscii(selectedObject->getNameInDocument()));
} else {
if (!msg.pSubName || msg.pSubName[0] == '\0')
return; return;
std::string element(msg.pSubName); std::string subName(msg.pSubName);
if (originalSelected(msg)) {
ui->lineOriginal->setText(QString::fromAscii(msg.pObjectName));
} else if (referenceSelectionMode &&
(subName.size() > 4 && subName.substr(0,4) == "Edge")) {
if (msg.Type == Gui::SelectionChanges::AddSelection) { if (strcmp(msg.pObjectName, getSupportObject()->getNameInDocument()) != 0)
if (element.substr(0,4) != "Edge")
return; return;
// TODO exitSelectionMode();
// if (originalElementName == "") { if (!blockUpdate) {
// Base::Console().Error("Element created by this pattern cannot be used for axis\n"); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
// return; std::vector<std::string> axes(1,subName);
// } pcPolarPattern->Axis.setValue(getSupportObject(), axes);
pcPolarPattern->StdAxis.setValue("");
std::vector<std::string> axes; recomputeFeature();
axes.push_back(element.c_str()); updateUI();
pcPolarPattern->Axis.setValue(getOriginalObject(), axes); }
else {
if (insideMultiTransform) { ui->buttonReference->setChecked(referenceSelectionMode);
if (parentTask->updateView()) ui->lineReference->setText(QString::fromAscii(subName.c_str()));
recomputeFeature(); }
} else
if (ui->checkBoxUpdateView->isChecked())
recomputeFeature();
if (!insideMultiTransform)
featureSelectionMode = true; // Jump back to selection of originals
showObject();
hideOriginals();
updateUI();
} }
} }
} }
void TaskPolarPatternParameters::onOriginalDeleted()
{
int row = ui->listFeatures->currentIndex().row();
TaskTransformedParameters::onOriginalDeleted(row);
ui->listFeatures->model()->removeRow(row);
}
void TaskPolarPatternParameters::onButtonX() { void TaskPolarPatternParameters::onButtonX() {
onStdAxis("X"); onStdAxis("X");
} }
@ -255,106 +230,108 @@ void TaskPolarPatternParameters::onButtonZ() {
} }
void TaskPolarPatternParameters::onCheckReverse(const bool on) { void TaskPolarPatternParameters::onCheckReverse(const bool on) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Reversed.setValue(on); pcPolarPattern->Reversed.setValue(on);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskPolarPatternParameters::onAngle(const double a) { void TaskPolarPatternParameters::onAngle(const double a) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Angle.setValue(a); pcPolarPattern->Angle.setValue(a);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskPolarPatternParameters::onOccurrences(const int n) { void TaskPolarPatternParameters::onOccurrences(const int n) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Occurrences.setValue(n); pcPolarPattern->Occurrences.setValue(n);
exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskPolarPatternParameters::onStdAxis(const std::string& axis) { void TaskPolarPatternParameters::onStdAxis(const std::string& axis) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->StdAxis.setValue(axis.c_str()); pcPolarPattern->StdAxis.setValue(axis.c_str());
pcPolarPattern->Axis.setValue(NULL); pcPolarPattern->Axis.setValue(NULL);
if (!insideMultiTransform)
featureSelectionMode = true; exitSelectionMode();
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskPolarPatternParameters::onButtonReference() void TaskPolarPatternParameters::onButtonReference(bool checked)
{ {
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); if (checked ) {
pcPolarPattern->StdAxis.setValue(""); hideObject();
featureSelectionMode = false; showOriginals();
hideObject(); referenceSelectionMode = true;
showOriginals(); Gui::Selection().clearSelection();
addReferenceSelectionGate(true, false);
} else {
exitSelectionMode();
}
updateUI(); updateUI();
} }
void TaskPolarPatternParameters::onUpdateView(bool on) void TaskPolarPatternParameters::onUpdateView(bool on)
{ {
ui->buttonX->blockSignals(!on); blockUpdate = !on;
ui->buttonY->blockSignals(!on); if (on) {
ui->buttonZ->blockSignals(!on); // Do the same like in TaskDlgPolarPatternParameters::accept() but without doCommand
ui->listFeatures->blockSignals(!on); PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
ui->checkReverse->blockSignals(!on);
ui->spinAngle->blockSignals(!on); std::string axis = getAxis();
ui->spinOccurrences->blockSignals(!on); if (!axis.empty()) {
std::vector<std::string> axes(1,axis);
pcPolarPattern->Axis.setValue(getSupportObject(),axes);
} else
pcPolarPattern->Axis.setValue(NULL);
std::string stdAxis = getStdAxis();
if (!stdAxis.empty())
pcPolarPattern->StdAxis.setValue(stdAxis.c_str());
else
pcPolarPattern->StdAxis.setValue(NULL);
pcPolarPattern->Reversed.setValue(getReverse());
pcPolarPattern->Angle.setValue(getAngle());
pcPolarPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
} }
const std::string TaskPolarPatternParameters::getStdAxis(void) const const std::string TaskPolarPatternParameters::getStdAxis(void) const
{ {
std::string stdAxis;
if (ui->buttonX->isChecked()) if (ui->buttonX->isChecked())
stdAxis = "X"; return std::string("X");
else if (ui->buttonY->isChecked()) else if (ui->buttonY->isChecked())
stdAxis = "Y"; return std::string("Y");
else if (ui->buttonZ->isChecked()) else if (ui->buttonZ->isChecked())
stdAxis = "Z"; return std::string("Z");
return std::string("");
if (!stdAxis.empty())
return std::string("\"") + stdAxis + "\"";
else
return std::string("");
} }
const QString TaskPolarPatternParameters::getAxis(void) const const std::string TaskPolarPatternParameters::getAxis(void) const
{ {
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject()); return ui->lineReference->text().toStdString();
App::DocumentObject* feature = pcPolarPattern->Axis.getValue();
if (feature == NULL)
return QString::fromUtf8("");
std::vector<std::string> axes = pcPolarPattern->Axis.getSubValues();
QString buf;
if ((feature != NULL) && !axes.empty()) {
buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(feature->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(axes.front().c_str()));
}
else
buf = QString::fromUtf8("");
return buf;
} }
const bool TaskPolarPatternParameters::getReverse(void) const const bool TaskPolarPatternParameters::getReverse(void) const
{ {
return ui->checkReverse->isChecked(); return ui->checkReverse->isChecked();
@ -370,6 +347,7 @@ const unsigned TaskPolarPatternParameters::getOccurrences(void) const
return ui->spinOccurrences->value(); return ui->spinOccurrences->value();
} }
TaskPolarPatternParameters::~TaskPolarPatternParameters() TaskPolarPatternParameters::~TaskPolarPatternParameters()
{ {
delete ui; delete ui;
@ -410,12 +388,16 @@ bool TaskDlgPolarPatternParameters::accept()
return false; return false;
TaskPolarPatternParameters* polarpatternParameter = static_cast<TaskPolarPatternParameters*>(parameter); TaskPolarPatternParameters* polarpatternParameter = static_cast<TaskPolarPatternParameters*>(parameter);
std::string axis = polarpatternParameter->getAxis().toStdString(); std::string axis = polarpatternParameter->getAxis();
if (!axis.empty()) if (!axis.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), axis.c_str()); QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromUtf8(polarpatternParameter->getSupportObject()->getNameInDocument()));
buf = buf.arg(QString::fromUtf8(axis.c_str()));
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), buf.toStdString().c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str());
std::string stdAxis = polarpatternParameter->getStdAxis(); std::string stdAxis = polarpatternParameter->getStdAxis();
if (!stdAxis.empty()) Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdAxis = \"%s\"",name.c_str(),stdAxis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.StdAxis = %s",name.c_str(),stdAxis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),polarpatternParameter->getReverse()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),polarpatternParameter->getReverse());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),polarpatternParameter->getAngle()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),polarpatternParameter->getAngle());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),polarpatternParameter->getOccurrences()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Occurrences = %u",name.c_str(),polarpatternParameter->getOccurrences());

View File

@ -56,8 +56,8 @@ public:
TaskPolarPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout); TaskPolarPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout);
virtual ~TaskPolarPatternParameters(); virtual ~TaskPolarPatternParameters();
const QString getAxis(void) const;
const std::string getStdAxis(void) const; const std::string getStdAxis(void) const;
const std::string getAxis(void) const;
const bool getReverse(void) const; const bool getReverse(void) const;
const double getAngle(void) const; const double getAngle(void) const;
const unsigned getOccurrences(void) const; const unsigned getOccurrences(void) const;
@ -70,8 +70,7 @@ private Q_SLOTS:
void onCheckReverse(const bool on); void onCheckReverse(const bool on);
void onAngle(const double a); void onAngle(const double a);
void onOccurrences(const int n); void onOccurrences(const int n);
virtual void onButtonReference(); void onButtonReference(const bool checked);
virtual void onOriginalDeleted();
virtual void onUpdateView(bool); virtual void onUpdateView(bool);
protected: protected:
@ -79,8 +78,8 @@ protected:
virtual void onSelectionChanged(const Gui::SelectionChanges& msg); virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private: private:
void updateUI();
void setupUI(); void setupUI();
void updateUI();
private: private:
Ui_TaskPolarPatternParameters* ui; Ui_TaskPolarPatternParameters* ui;

View File

@ -15,7 +15,18 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QListWidget" name="listFeatures"/> <layout class="QHBoxLayout" name="horizontalLayoutOriginal">
<item>
<widget class="QLabel" name="labelOriginal">
<property name="text">
<string>Original feature</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineOriginal"/>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -52,6 +63,9 @@
<property name="text"> <property name="text">
<string>Direction</string> <string>Direction</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -132,6 +146,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -29,6 +29,7 @@
#include "ui_TaskScaledParameters.h" #include "ui_TaskScaledParameters.h"
#include "TaskScaledParameters.h" #include "TaskScaledParameters.h"
#include "TaskMultiTransformParameters.h"
#include <App/Application.h> #include <App/Application.h>
#include <App/Document.h> #include <App/Document.h>
#include <Gui/Application.h> #include <Gui/Application.h>
@ -41,7 +42,6 @@
#include <Gui/Command.h> #include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureScaled.h> #include <Mod/PartDesign/App/FeatureScaled.h>
#include <Mod/Sketcher/App/SketchObject.h> #include <Mod/Sketcher/App/SketchObject.h>
#include "TaskMultiTransformParameters.h"
using namespace PartDesignGui; using namespace PartDesignGui;
using namespace Gui; using namespace Gui;
@ -62,7 +62,7 @@ TaskScaledParameters::TaskScaledParameters(ViewProviderTransformed *TransformedV
ui->buttonOK->hide(); ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true); ui->checkBoxUpdateView->setEnabled(true);
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -79,10 +79,11 @@ TaskScaledParameters::TaskScaledParameters(TaskMultiTransformParameters *parentT
layout->addWidget(proxy); layout->addWidget(proxy);
ui->buttonOK->setEnabled(true); ui->buttonOK->setEnabled(true);
ui->listFeatures->hide(); ui->labelOriginal->hide();
ui->lineOriginal->hide();
ui->checkBoxUpdateView->hide(); ui->checkBoxUpdateView->hide();
updateUIinProgress = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!! blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI(); setupUI();
} }
@ -95,30 +96,19 @@ void TaskScaledParameters::setupUI()
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool))); this, SLOT(onUpdateView(bool)));
// TODO: The following code could be generic in TaskTransformedParameters
// if it were possible to make ui_TaskScaledParameters a subclass of
// ui_TaskTransformedParameters
// ---------------------
// Add a context menu to the listview of the originals to delete items
QAction* action = new QAction(tr("Delete"), ui->listFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onOriginalDeleted()));
ui->listFeatures->addAction(action);
ui->listFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Get the feature data // Get the feature data
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject()); PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
std::vector<App::DocumentObject*> originals = pcScaled->Originals.getValues(); std::vector<App::DocumentObject*> originals = pcScaled->Originals.getValues();
// Fill data into dialog elements // Fill data into dialog elements
ui->listFeatures->setEnabled(true); ui->lineOriginal->setEnabled(false);
ui->listFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++) for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{ {
if ((*i) != NULL) if ((*i) != NULL) { // find the first valid original
ui->listFeatures->addItem(QString::fromAscii((*i)->getNameInDocument())); ui->lineOriginal->setText(QString::fromAscii((*i)->getNameInDocument()));
break;
}
} }
QMetaObject::invokeMethod(ui->listFeatures, "setFocus", Qt::QueuedConnection);
// --------------------- // ---------------------
ui->spinFactor->setEnabled(true); ui->spinFactor->setEnabled(true);
@ -129,8 +119,9 @@ void TaskScaledParameters::setupUI()
void TaskScaledParameters::updateUI() void TaskScaledParameters::updateUI()
{ {
if (updateUIinProgress) return; if (blockUpdate)
updateUIinProgress = true; return;
blockUpdate = true;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject()); PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
@ -140,56 +131,45 @@ void TaskScaledParameters::updateUI()
ui->spinFactor->setValue(factor); ui->spinFactor->setValue(factor);
ui->spinOccurrences->setValue(occurrences); ui->spinOccurrences->setValue(occurrences);
updateUIinProgress = false; blockUpdate = false;
} }
void TaskScaledParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskScaledParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject()); if (originalSelected(msg)) {
App::DocumentObject* selectedObject = pcScaled->getDocument()->getActiveObject(); App::DocumentObject* selectedObject = TransformedView->getObject()->getDocument()->getActiveObject();
if ((selectedObject == NULL) || !selectedObject->isDerivedFrom(Part::Feature::getClassTypeId())) ui->lineOriginal->setText(QString::fromAscii(selectedObject->getNameInDocument()));
return;
if (featureSelectionMode) {
if (originalSelected(msg))
ui->listFeatures->addItem(QString::fromAscii(selectedObject->getNameInDocument()));
} else {
return;
} }
} }
void TaskScaledParameters::onOriginalDeleted()
{
int row = ui->listFeatures->currentIndex().row();
TaskTransformedParameters::onOriginalDeleted(row);
ui->listFeatures->model()->removeRow(row);
}
void TaskScaledParameters::onFactor(const double f) { void TaskScaledParameters::onFactor(const double f) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject()); PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(f); pcScaled->Factor.setValue(f);
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskScaledParameters::onOccurrences(const int n) { void TaskScaledParameters::onOccurrences(const int n) {
if (updateUIinProgress) return; if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject()); PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Occurrences.setValue(n); pcScaled->Occurrences.setValue(n);
updateUI(); updateUI();
if (insideMultiTransform && !parentTask->updateView())
return;
recomputeFeature(); recomputeFeature();
} }
void TaskScaledParameters::onUpdateView(bool on) void TaskScaledParameters::onUpdateView(bool on)
{ {
ui->listFeatures->blockSignals(!on); blockUpdate = !on;
ui->spinFactor->blockSignals(!on); if (on) {
ui->spinOccurrences->blockSignals(!on); // Do the same like in TaskDlgScaledParameters::accept() but without doCommand
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(getFactor());
pcScaled->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
} }
const double TaskScaledParameters::getFactor(void) const const double TaskScaledParameters::getFactor(void) const
@ -202,6 +182,7 @@ const unsigned TaskScaledParameters::getOccurrences(void) const
return ui->spinOccurrences->value(); return ui->spinOccurrences->value();
} }
TaskScaledParameters::~TaskScaledParameters() TaskScaledParameters::~TaskScaledParameters()
{ {
delete ui; delete ui;

View File

@ -62,8 +62,6 @@ public:
private Q_SLOTS: private Q_SLOTS:
void onFactor(const double f); void onFactor(const double f);
void onOccurrences(const int n); void onOccurrences(const int n);
virtual void onButtonReference() {}
virtual void onOriginalDeleted();
virtual void onUpdateView(bool); virtual void onUpdateView(bool);
protected: protected:
@ -71,8 +69,8 @@ protected:
virtual void onSelectionChanged(const Gui::SelectionChanges& msg); virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private: private:
void updateUI();
void setupUI(); void setupUI();
void updateUI();
private: private:
Ui_TaskScaledParameters* ui; Ui_TaskScaledParameters* ui;

View File

@ -15,7 +15,18 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QListWidget" name="listFeatures"/> <layout class="QHBoxLayout" name="horizontalLayoutOriginal">
<item>
<widget class="QLabel" name="labelOriginal">
<property name="text">
<string>Original feature</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineOriginal"/>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
@ -86,6 +97,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "ui_TaskTransformedMessages.h"
#include "TaskTransformedMessages.h"
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <boost/bind.hpp>
#include "ViewProviderTransformed.h"
using namespace PartDesignGui;
using namespace Gui::TaskView;
TaskTransformedMessages::TaskTransformedMessages(ViewProviderTransformed *transformedView_)
: TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("Transformed feature messages"),true, 0),
transformedView(transformedView_)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskTransformedMessages();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
connectionDiagnosis = transformedView->signalDiagnosis.connect(boost::bind(&PartDesignGui::TaskTransformedMessages::slotDiagnosis, this,_1));
}
TaskTransformedMessages::~TaskTransformedMessages()
{
connectionDiagnosis.disconnect();
delete ui;
}
void TaskTransformedMessages::slotDiagnosis(QString msg)
{
ui->labelTransformationStatus->setText(msg);
}
#include "moc_TaskTransformedMessages.cpp"

View File

@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskTransformedMessages_H
#define GUI_TASKVIEW_TaskTransformedMessages_H
#include <Gui/TaskView/TaskView.h>
#include <boost/signals.hpp>
class Ui_TaskTransformedMessages;
typedef boost::signals::connection Connection;
namespace App {
class Property;
}
namespace PartDesignGui {
class ViewProviderTransformed;
class TaskTransformedMessages : public Gui::TaskView::TaskBox
{
Q_OBJECT
public:
TaskTransformedMessages(ViewProviderTransformed *transformedView);
~TaskTransformedMessages();
void slotDiagnosis(QString msg);
private Q_SLOTS:
protected:
ViewProviderTransformed *transformedView;
Connection connectionDiagnosis;
private:
QWidget* proxy;
Ui_TaskTransformedMessages* ui;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TaskTransformedMessages_H

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskTransformedMessages</class>
<widget class="QWidget" name="TaskTransformedMessages">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>228</width>
<height>89</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="labelTransformationStatus">
<property name="font">
<font>
<family>Bitstream Charter</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>No message</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -24,6 +24,10 @@
#ifndef _PreComp_ #ifndef _PreComp_
# include <QMessageBox> # include <QMessageBox>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS.hxx>
# include <BRepAdaptor_Surface.hxx>
#endif #endif
#include "TaskTransformedParameters.h" #include "TaskTransformedParameters.h"
@ -55,10 +59,9 @@ TaskTransformedParameters::TaskTransformedParameters(ViewProviderTransformed *Tr
TransformedView(TransformedView), TransformedView(TransformedView),
parentTask(NULL), parentTask(NULL),
insideMultiTransform(false), insideMultiTransform(false),
updateUIinProgress(false) blockUpdate(false)
{ {
// Start in feature selection mode originalSelectionMode = false;
featureSelectionMode = true;
} }
TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameters *parentTask) TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameters *parentTask)
@ -66,30 +69,30 @@ TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameter
TransformedView(NULL), TransformedView(NULL),
parentTask(parentTask), parentTask(parentTask),
insideMultiTransform(true), insideMultiTransform(true),
updateUIinProgress(false) blockUpdate(false)
{ {
// Start in reference selection mode and stay there! Feature selection makes // Original feature selection makes no sense inside a MultiTransform
// no sense inside a MultiTransform originalSelectionMode = false;
featureSelectionMode = false;
} }
const bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& msg) const bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& msg)
{ {
if (featureSelectionMode && (msg.Type == Gui::SelectionChanges::AddSelection)) { if (msg.Type == Gui::SelectionChanges::AddSelection && originalSelectionMode) {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
App::DocumentObject* selectedObject = pcTransformed->getDocument()->getActiveObject(); if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
if (!selectedObject->isDerivedFrom(PartDesign::Additive::getClassTypeId()) &&
!selectedObject->isDerivedFrom(PartDesign::Subtractive::getClassTypeId()))
return false;
if (TransformedView->getObject() == pcTransformed)
return false; return false;
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues(); PartDesign::Transformed* pcTransformed = getObject();
App::DocumentObject* selectedObject = pcTransformed->getDocument()->getObject(msg.pObjectName);
if (selectedObject->isDerivedFrom(PartDesign::Additive::getClassTypeId()) ||
selectedObject->isDerivedFrom(PartDesign::Subtractive::getClassTypeId())) {
if (std::find(originals.begin(), originals.end(), selectedObject) == originals.end()) { // Do the same like in TaskDlgTransformedParameters::accept() but without doCommand
originals.push_back(selectedObject); std::vector<App::DocumentObject*> originals(1,selectedObject);
pcTransformed->Originals.setValues(originals); pcTransformed->Originals.setValues(originals);
pcTransformed->getDocument()->recomputeFeature(pcTransformed); recomputeFeature();
originalSelectionMode = false;
return true; return true;
} }
} }
@ -97,15 +100,6 @@ const bool TaskTransformedParameters::originalSelected(const Gui::SelectionChang
return false; return false;
} }
void TaskTransformedParameters::onOriginalDeleted(const int row)
{
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + row);
pcTransformed->Originals.setValues(originals);
pcTransformed->getDocument()->recomputeFeature(pcTransformed);
}
PartDesign::Transformed *TaskTransformedParameters::getObject() const PartDesign::Transformed *TaskTransformedParameters::getObject() const
{ {
@ -118,10 +112,10 @@ PartDesign::Transformed *TaskTransformedParameters::getObject() const
void TaskTransformedParameters::recomputeFeature() void TaskTransformedParameters::recomputeFeature()
{ {
if (insideMultiTransform) { if (insideMultiTransform) {
// redirect recompute and let the parent decide if recompute has to be blocked
parentTask->recomputeFeature(); parentTask->recomputeFeature();
} else { } else if (!blockUpdate) {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject()); TransformedView->recomputeFeature();
pcTransformed->getDocument()->recomputeFeature(pcTransformed);
} }
} }
@ -137,13 +131,13 @@ const std::vector<App::DocumentObject*> TaskTransformedParameters::getOriginals(
} }
} }
App::DocumentObject* TaskTransformedParameters::getOriginalObject() const App::DocumentObject* TaskTransformedParameters::getSupportObject() const
{ {
if (insideMultiTransform) { if (insideMultiTransform) {
return parentTask->getOriginalObject(); return parentTask->getSupportObject();
} else { } else {
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject()); PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(TransformedView->getObject());
return pcTransformed->getOriginalObject(); return pcTransformed->getSupportObject();
} }
} }
@ -189,16 +183,66 @@ void TaskTransformedParameters::showOriginals()
} }
} }
void TaskTransformedParameters::exitSelectionMode()
{
originalSelectionMode = false;
referenceSelectionMode = false;
Gui::Selection().rmvSelectionGate();
showObject();
hideOriginals();
}
class ReferenceSelection : public Gui::SelectionFilterGate
{
const App::DocumentObject* support;
bool edge, plane;
public:
ReferenceSelection(const App::DocumentObject* support_, bool edge_, bool plane_)
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0),
support(support_), edge(edge_), plane(plane_)
{
}
bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
{
if (!sSubName || sSubName[0] == '\0')
return false;
if (pObj != support)
return false;
std::string subName(sSubName);
if (edge && subName.size() > 4 && subName.substr(0,4) == "Edge")
return true;
if (plane && subName.size() > 4 && subName.substr(0,4) == "Face") {
const Part::TopoShape &shape = static_cast<const Part::Feature*>(support)->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(subName.c_str());
const TopoDS_Face& face = TopoDS::Face(sh);
if (!face.IsNull()) {
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() == GeomAbs_Plane)
return true;
}
}
return false;
}
};
void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face)
{
Gui::Selection().addSelectionGate(new ReferenceSelection(getSupportObject(), edge, face));
}
//************************************************************************** //**************************************************************************
//************************************************************************** //**************************************************************************
// TaskDialog // TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgTransformedParameters::TaskDlgTransformedParameters(ViewProviderTransformed *TransformedView) TaskDlgTransformedParameters::TaskDlgTransformedParameters(ViewProviderTransformed *TransformedView_)
: TaskDialog(),TransformedView(TransformedView) : TaskDialog(), TransformedView(TransformedView_)
{ {
assert(TransformedView); assert(TransformedView);
message = new TaskTransformedMessages(TransformedView);
Content.push_back(message);
} }
//==== calls from the TaskView =============================================================== //==== calls from the TaskView ===============================================================

View File

@ -28,6 +28,7 @@
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h> #include <Gui/TaskView/TaskDialog.h>
#include "TaskTransformedMessages.h"
#include "ViewProviderTransformed.h" #include "ViewProviderTransformed.h"
namespace PartDesign { namespace PartDesign {
@ -59,18 +60,15 @@ public:
{} {}
const std::vector<App::DocumentObject*> getOriginals(void) const; const std::vector<App::DocumentObject*> getOriginals(void) const;
/// Get the support object either of the object associated with this feature or with the parent feature (MultiTransform mode)
App::DocumentObject* getSupportObject() const;
protected Q_SLOTS: protected Q_SLOTS:
virtual void onButtonReference() = 0;
virtual void onOriginalDeleted() = 0;
virtual void onUpdateView(bool) = 0;
/// Connect the subTask OK button to the MultiTransform task /// Connect the subTask OK button to the MultiTransform task
virtual void onSubTaskButtonOK() {} virtual void onSubTaskButtonOK() {}
protected: protected:
void onOriginalDeleted(const int row);
const bool originalSelected(const Gui::SelectionChanges& msg); const bool originalSelected(const Gui::SelectionChanges& msg);
/// Get the TransformedFeature object associated with this task /// Get the TransformedFeature object associated with this task
@ -78,14 +76,14 @@ protected:
PartDesign::Transformed *getObject() const; PartDesign::Transformed *getObject() const;
/// Recompute either this feature or the parent feature (MultiTransform mode) /// Recompute either this feature or the parent feature (MultiTransform mode)
void recomputeFeature(); void recomputeFeature();
/// Get the original object either of the object associated with this feature or with the parent feature (MultiTransform mode)
App::DocumentObject* getOriginalObject() const;
void hideObject(); void hideObject();
void showObject(); void showObject();
void hideOriginals(); void hideOriginals();
void showOriginals(); void showOriginals();
void exitSelectionMode();
void addReferenceSelectionGate(bool edge, bool face);
protected: protected:
virtual void changeEvent(QEvent *e) = 0; virtual void changeEvent(QEvent *e) = 0;
virtual void onSelectionChanged(const Gui::SelectionChanges& msg) = 0; virtual void onSelectionChanged(const Gui::SelectionChanges& msg) = 0;
@ -93,14 +91,16 @@ protected:
protected: protected:
QWidget* proxy; QWidget* proxy;
ViewProviderTransformed *TransformedView; ViewProviderTransformed *TransformedView;
bool featureSelectionMode;
bool originalSelectionMode;
bool referenceSelectionMode;
/// The MultiTransform parent task of this task /// The MultiTransform parent task of this task
TaskMultiTransformParameters* parentTask; TaskMultiTransformParameters* parentTask;
/// Flag indicating whether this object is a container for MultiTransform /// Flag indicating whether this object is a container for MultiTransform
bool insideMultiTransform; bool insideMultiTransform;
/// Lock updateUI() so that no unnecessary recomputeFeatures() are triggered /// Lock updateUI(), applying changes to the underlying feature and calling recomputeFeature()
bool updateUIinProgress; bool blockUpdate;
}; };
/// simulation dialog for the TaskView /// simulation dialog for the TaskView
@ -138,6 +138,7 @@ protected:
ViewProviderTransformed *TransformedView; ViewProviderTransformed *TransformedView;
TaskTransformedParameters *parameter; TaskTransformedParameters *parameter;
TaskTransformedMessages *message;
}; };
} //namespace PartDesignGui } //namespace PartDesignGui

View File

@ -112,3 +112,30 @@ const bool ViewProviderTransformed::checkDlgOpen(TaskDlgTransformedParameters* t
// Continue (usually in virtual method setEdit()) // Continue (usually in virtual method setEdit())
return true; return true;
} }
void ViewProviderTransformed::recomputeFeature(void)
{
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(getObject());
pcTransformed->getDocument()->recomputeFeature(pcTransformed);
const std::vector<App::DocumentObjectExecReturn*> log = pcTransformed->getDocument()->getRecomputeLog();
unsigned rejected = pcTransformed->getRejectedTransformations().size();
QString msg = QString::fromAscii("%1");
if (rejected > 0) {
msg = QString::fromLatin1("<font color='orange'>%1<br/></font>\r\n%2");
if (rejected == 1)
msg = msg.arg(QObject::tr("One transformed shape does not intersect support"));
else {
msg = msg.arg(QObject::tr("%1 transformed shapes do not intersect support"));
msg = msg.arg(rejected);
}
}
if (log.size() > 0) {
msg = msg.arg(QString::fromLatin1("<font color='red'>%1<br/></font>"));
msg = msg.arg(QString::fromStdString(log.back()->Why));
} else {
msg = msg.arg(QString::fromLatin1("<font color='green'>%1<br/></font>"));
msg = msg.arg(QObject::tr("Transformation succeeded"));
}
signalDiagnosis(msg);
}

View File

@ -48,6 +48,9 @@ public:
virtual bool onDelete(const std::vector<std::string> &); virtual bool onDelete(const std::vector<std::string> &);
/// signals if the transformation contains errors
boost::signal<void (QString msg)> signalDiagnosis;
// The feature name of the subclass // The feature name of the subclass
std::string featureName; std::string featureName;
@ -56,6 +59,8 @@ protected:
virtual void unsetEdit(int ModNum); virtual void unsetEdit(int ModNum);
const bool checkDlgOpen(TaskDlgTransformedParameters* transformedDlg); const bool checkDlgOpen(TaskDlgTransformedParameters* transformedDlg);
public:
void recomputeFeature();
}; };

View File

@ -125,10 +125,10 @@ void Workbench::activated()
"PartDesign_MultiTransform", "PartDesign_MultiTransform",
0}; 0};
Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( Watcher.push_back(new Gui::TaskView::TaskWatcherCommands(
"SELECT Part::Feature", "SELECT PartDesign::SketchBased",
Transformed, Transformed,
"Transformation tools", "Transformation tools",
"PartDesign_Mirrored" "PartDesign_MultiTransform"
)); ));
const char* Empty[] = { const char* Empty[] = {