Allow selecting back of base planes, miscellaneous fixes

This commit is contained in:
jrheinlaender 2013-05-09 17:25:43 +04:30 committed by Stefan Tröger
parent 0e8921c21f
commit fe2e490645
10 changed files with 54 additions and 22 deletions

View File

@ -46,7 +46,7 @@ App::Document *ActiveAppDoc =0;
Gui::ViewProviderDocumentObject *ActiveVp =0;
// The names of the base planes. Note: The user-visible label is different from this
const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneYZ", "BaseplaneXZ"};
const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"};
}

View File

@ -90,10 +90,8 @@ void Part2DObject::positionBySupport(void)
Base::Vector3d dir;
Place.getRotation().multVec(Base::Vector3d(0,0,1),dir);
const std::vector<std::string> &sub = Support.getSubValues();
if (!sub.empty() && (sub[0] == "back")) {
if (!sub.empty() && (sub[0] == "back"))
Reverse = true;
dir *= -1.0;
}
// Set placement identical to the way it used to be done in the Sketcher::SketchOrientationDialog
if (dir == Base::Vector3d(0,0,1)) {
@ -107,7 +105,10 @@ void Part2DObject::positionBySupport(void)
Place = Base::Placement(Base::Vector3d(0,0,0),Base::Rotation(Reverse ? -0.5 : 0.5,0.5,0.5, Reverse ? -0.5 : 0.5));
}
Reverse = false; // We already reversed...
if (Reverse) {
dir *= -1.0;
Reverse = false; // We already reversed...
}
Place.getRotation().multVec(Base::Vector3d(0,0,1),dir);
Base::Vector3d pos = Place.getPosition();

View File

@ -33,7 +33,7 @@ namespace PartDesign
class Feature;
class Body : public Part::BodyBase
class PartDesignExport Body : public Part::BodyBase
{
PROPERTY_HEADER(PartDesign::Body);

View File

@ -11,6 +11,7 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${OCC_INCLUDE_DIR}
${QT_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}

View File

@ -121,11 +121,11 @@ void CmdPartDesignBody::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[0]);
doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str());
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[1]);
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),-90))");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str());
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[2]);
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str());
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[2]);
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str());
// ... and put them in the 'Origin' group
doCommand(Doc,"App.activeDocument().addObject('App::DocumentObjectGroup','%s')", QObject::tr("Origin").toStdString().c_str());
for (unsigned i = 0; i < 3; i++)
@ -612,18 +612,19 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
// If there is more than one possibility, show dialog and let user pick plane
bool reversed = false;
if (validPlanes > 1) {
PartDesignGui::FeaturePickDialog Dlg(planes, status);
if ((Dlg.exec() != QDialog::Accepted) || (planes = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
firstValidPlane = planes.begin();
reversed = Dlg.getReverse();
}
// TODO: Allow user to choose front or back of the plane
App::Plane* plane = static_cast<App::Plane*>(*firstValidPlane);
std::string FeatName = getUniqueObjectName("Sketch");
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() + ", ['front'])";
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() +
", ['" + (reversed ? "back" : "front") + "'])";
openCommand("Create a new Sketch");
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());

View File

@ -60,12 +60,14 @@ FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects,
{
ui->setupUi(this);
connect(ui->checkReverse, SIGNAL(toggled(bool)), this, SLOT(onCheckReverse(bool)));
connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherBody(bool)));
connect(ui->checkOtherFeature, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherFeature(bool)));
connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
ui->checkReverse->setChecked(false);
ui->checkOtherBody->setChecked(false);
ui->checkOtherBody->setEnabled(false); // TODO: implement
ui->checkOtherFeature->setChecked(false);
@ -114,6 +116,10 @@ void FeaturePickDialog::updateList()
}
}
void FeaturePickDialog::onCheckReverse(bool checked)
{
}
void FeaturePickDialog::onCheckOtherFeature(bool checked)
{
ui->radioIndependent->setEnabled(checked);
@ -139,6 +145,11 @@ void FeaturePickDialog::onUpdate(bool)
updateList();
}
bool FeaturePickDialog::getReverse()
{
return ui->checkReverse->isChecked();
}
std::vector<App::DocumentObject*> FeaturePickDialog::getFeatures() {
std::vector<App::DocumentObject*> result;

View File

@ -49,14 +49,17 @@ public:
~FeaturePickDialog();
std::vector<App::DocumentObject*> getFeatures();
bool getReverse();
void accept();
protected Q_SLOTS:
void onCheckReverse(bool);
void onCheckOtherFeature(bool);
void onCheckOtherBody(bool);
void onUpdate(bool);
private:
Ui_FeaturePickDialog* ui;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>318</width>
<height>357</height>
<height>398</height>
</rect>
</property>
<property name="windowTitle">
@ -17,10 +17,24 @@
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QCheckBox" name="checkReverse">
<property name="text">
<string>Reverse direction</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkOtherBody">
<property name="text">
<string>Allow sketch from other Body</string>
<string>Allow feature from other Body</string>
</property>
</widget>
</item>

View File

@ -162,10 +162,10 @@ void switchToDocument(const App::Document* doc)
if (SketchVector == Base::Vector3d(0,0,1)) {
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,['%s'])",
sketch->getNameInDocument(), BaseplaneNames[0], side.c_str());
} else if (SketchVector == Base::Vector3d(1,0,0)) {
} else if (SketchVector == Base::Vector3d(0,1,0)) {
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,['%s'])",
sketch->getNameInDocument(), BaseplaneNames[1], side.c_str());
} else if (SketchVector == Base::Vector3d(0,1,0)) {
} else if (SketchVector == Base::Vector3d(1,0,0)) {
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,['%s'])",
sketch->getNameInDocument(), BaseplaneNames[2], side.c_str());
} else {
@ -206,11 +206,11 @@ void switchToDocument(const App::Document* doc)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[0]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[1]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[2]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", PartDesignGui::BaseplaneNames[2]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str());
// ... and put them in the 'Origin' group
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::DocumentObjectGroup','%s')", QObject::tr("Origin").toStdString().c_str());
for (unsigned i = 0; i < 3; i++)

View File

@ -22,8 +22,9 @@
#***************************************************************************
import FreeCADGui
FreeCADGui.activateWorkbench("PartDesignWorkbench")
Gui.activateWorkbench("PartDesignWorkbench")
App.newDocument()
# Make the planes properly visible
FreeCADGui.activeDocument().activeView().viewAxometric()
FreeCADGui.SendMsgToActiveView("ViewFit")
#Gui.ActiveDocument.ActiveView.setCameraOrientation(App.ActiveDocument.BaseplaneXY.Placement.Rotation.Q)
#Gui.activeDocument().activeView().viewAxometric()
#Gui.SendMsgToActiveView("ViewFit")