ask user if he creates inter part/body references
This commit is contained in:
parent
655bf961be
commit
d5e035741a
|
@ -83,6 +83,7 @@ set(PartDesignGui_UIC_SRCS
|
|||
TaskPipeOrientation.ui
|
||||
TaskPipeScaling.ui
|
||||
TaskLoftParameters.ui
|
||||
DlgReference.ui
|
||||
)
|
||||
qt4_wrap_ui(PartDesignGui_UIC_HDRS ${PartDesignGui_UIC_SRCS})
|
||||
|
||||
|
|
|
@ -62,6 +62,9 @@
|
|||
#include "Utils.h"
|
||||
#include "WorkflowManager.h"
|
||||
|
||||
// TODO Remove this header after fixing code so it won;t be needed here (2015-10-20, Fat-Zer)
|
||||
#include "ui_DlgReference.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
@ -90,12 +93,52 @@ void UnifiedDatumCommand(Gui::Command &cmd, Base::Type type, std::string name)
|
|||
bEditSelected = true;
|
||||
}
|
||||
|
||||
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */false);
|
||||
|
||||
if (bEditSelected) {
|
||||
std::string tmp = std::string("Edit ")+name;
|
||||
cmd.openCommand(tmp.c_str());
|
||||
cmd.doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')",support.getValue()->getNameInDocument());
|
||||
} else {
|
||||
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */false);
|
||||
} else if (pcActiveBody) {
|
||||
|
||||
auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
|
||||
|
||||
// TODO Check how this will work outside of a body (2015-10-20, Fat-Zer)
|
||||
//check the prerequisites for the selected objects
|
||||
//the user has to decide which option we should take if external references are used
|
||||
bool ext = false;
|
||||
for(App::DocumentObject* obj : support.getValues()) {
|
||||
if(!pcActiveBody->hasFeature(obj))
|
||||
ext = true;
|
||||
}
|
||||
// TODO rewrite this to be shared with CmdPartDesignNewSketch::activated() (2015-10-20, Fat-Zer)
|
||||
if(ext) {
|
||||
QDialog* dia = new QDialog;
|
||||
Ui_Dialog dlg;
|
||||
dlg.setupUi(dia);
|
||||
dia->setModal(true);
|
||||
int result = dia->exec();
|
||||
if(result == QDialog::DialogCode::Rejected)
|
||||
return;
|
||||
else if(!dlg.radioXRef->isChecked()) {
|
||||
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
std::vector<std::string> subs = support.getSubValues();
|
||||
int index = 0;
|
||||
for(App::DocumentObject* obj : support.getValues()) {
|
||||
|
||||
objs.push_back(PartDesignGui::TaskFeaturePick::makeCopy(obj, subs[index], dlg.radioIndependent->isChecked()));
|
||||
auto oBody = PartDesignGui::getBodyFor(obj, false);
|
||||
if (oBody && pcActiveBody) {
|
||||
pcActiveBody->addFeature(objs.back());
|
||||
} else if (pcActivePart) {
|
||||
pcActivePart->addObject(objs.back());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
std::string FeatName = cmd.getUniqueObjectName(name.c_str());
|
||||
|
||||
|
@ -246,6 +289,7 @@ void CmdPartDesignShapeBinder::activated(int iMsg)
|
|||
}
|
||||
|
||||
if (bEditSelected) {
|
||||
// TODO probably we not should handle edit here (2015-10-26, Fat-Zer)
|
||||
std::string tmp = std::string("Edit ShapeBinder");
|
||||
openCommand(tmp.c_str());
|
||||
doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')",
|
||||
|
@ -254,7 +298,7 @@ void CmdPartDesignShapeBinder::activated(int iMsg)
|
|||
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true);
|
||||
if (pcActiveBody == 0)
|
||||
return;
|
||||
|
||||
|
||||
std::string FeatName = getUniqueObjectName("ShapeBinder");
|
||||
std::string tmp = std::string("Create ShapeBinder");
|
||||
|
||||
|
@ -385,16 +429,30 @@ void CmdPartDesignNewSketch::activated(int iMsg)
|
|||
if (!pcActiveBody->hasFeature(obj)) {
|
||||
if ( !obj->isDerivedFrom ( App::Plane::getClassTypeId() ) ) {
|
||||
// TODO check here if the plane associated with right part/body (2015-09-01, Fat-Zer)
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from other body"),
|
||||
QObject::tr("You have to select a face or plane from the active body!"));
|
||||
return;
|
||||
|
||||
auto pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
|
||||
|
||||
//check the prerequisites for the selected objects
|
||||
//the user has to decide which option we should take if external references are used
|
||||
// TODO share this with UnifiedDatumCommand() (2015-10-20, Fat-Zer)
|
||||
QDialog* dia = new QDialog;
|
||||
Ui_Dialog dlg;
|
||||
dlg.setupUi(dia);
|
||||
dia->setModal(true);
|
||||
int result = dia->exec();
|
||||
if(result == QDialog::DialogCode::Rejected)
|
||||
return;
|
||||
else if(!dlg.radioXRef->isChecked()) {
|
||||
|
||||
const std::vector<std::string> &sub = FaceFilter.Result[0][0].getSubNames();
|
||||
auto copy = PartDesignGui::TaskFeaturePick::makeCopy(obj, sub[0], dlg.radioIndependent->isChecked());
|
||||
auto oBody = PartDesignGui::getBodyFor(obj, false);
|
||||
if(oBody)
|
||||
pcActiveBody->addFeature(copy);
|
||||
else
|
||||
pcActivePart->addObject(copy);
|
||||
}
|
||||
}
|
||||
} else if (!obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())
|
||||
&& pcActiveBody->Tip.getValue () != obj) {
|
||||
// TODO checkme why it's forbidden!? (2015-08-05, Fat-Zer)
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from inactive feature"),
|
||||
QObject::tr("You can only use the Tip as sketch support"));
|
||||
return;
|
||||
}
|
||||
|
||||
// create Sketch on Face or Plane
|
||||
|
@ -738,11 +796,35 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which,
|
|||
s == PartDesignGui::TaskFeaturePick::notInBody;
|
||||
}
|
||||
) != status.end();
|
||||
// TODO Clean this up (2015-10-20, Fat-Zer)
|
||||
auto* pcActiveBody = PartDesignGui::getBody(false);
|
||||
if(pcActiveBody && !bNoSketchWasSelected && ext) {
|
||||
|
||||
auto* pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
|
||||
|
||||
// TODO share this with UnifiedDatumCommand() (2015-10-20, Fat-Zer)
|
||||
QDialog* dia = new QDialog;
|
||||
Ui_Dialog dlg;
|
||||
dlg.setupUi(dia);
|
||||
dia->setModal(true);
|
||||
int result = dia->exec();
|
||||
if(result == QDialog::DialogCode::Rejected)
|
||||
return;
|
||||
else if(!dlg.radioXRef->isChecked()) {
|
||||
|
||||
auto copy = PartDesignGui::TaskFeaturePick::makeCopy(sketches[0], "", dlg.radioIndependent->isChecked());
|
||||
auto oBody = PartDesignGui::getBodyFor(sketches[0], false);
|
||||
if(oBody)
|
||||
pcActiveBody->addFeature(copy);
|
||||
else
|
||||
pcActivePart->addObject(copy);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If there is more than one selection/possibility, show dialog and let user pick sketch
|
||||
if ((bNoSketchWasSelected && validSketches > 1) ||
|
||||
(!bNoSketchWasSelected && sketches.size() > 1) ||
|
||||
(!bNoSketchWasSelected && ext) ) {
|
||||
(!bNoSketchWasSelected && sketches.size() > 1)) {
|
||||
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
PartDesignGui::TaskDlgFeaturePick *pickDlg = qobject_cast<PartDesignGui::TaskDlgFeaturePick *>(dlg);
|
||||
|
@ -847,7 +929,7 @@ CmdPartDesignPocket::CmdPartDesignPocket()
|
|||
sGroup = QT_TR_NOOP("PartDesign");
|
||||
sMenuText = QT_TR_NOOP("Pocket");
|
||||
sToolTipText = QT_TR_NOOP("Create a pocket with the selected sketch");
|
||||
sWhatsThis = "PartDesign_Pocket";
|
||||
sWhatsThis = sToolTipText;
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "PartDesign_Pocket";
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
126
src/Mod/PartDesign/Gui/DlgReference.ui
Normal file
126
src/Mod/PartDesign/Gui/DlgReference.ui
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>487</width>
|
||||
<height>243</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>You selected geometries which are not part of the active body. Please define how to handle those selections. If you do not want those references cancel the command.</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioIndependent">
|
||||
<property name="text">
|
||||
<string>Make independent copy (recommended)</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioDependent">
|
||||
<property name="text">
|
||||
<string>Make dependent copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioXRef">
|
||||
<property name="text">
|
||||
<string>Create cross-reference</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<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>Dialog</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>Dialog</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>
|
|
@ -222,7 +222,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
|
|||
if(*st == otherBody) {
|
||||
|
||||
if(ui->bodyRadioIndependent->isChecked()) {
|
||||
auto copy = makeCopy(obj, true);
|
||||
auto copy = makeCopy(obj, "", true);
|
||||
activeBody->addFeature(copy);
|
||||
result.push_back(copy);
|
||||
} else {
|
||||
|
@ -232,7 +232,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
|
|||
else if(*st == otherPart) {
|
||||
|
||||
if(!ui->partRadioXRef->isChecked()) {
|
||||
auto copy = makeCopy(obj, ui->partRadioIndependent->isChecked());
|
||||
auto copy = makeCopy(obj, "", ui->partRadioIndependent->isChecked());
|
||||
|
||||
auto oBody = PartDesignGui::getBodyFor(obj, false);
|
||||
if(oBody)
|
||||
|
@ -246,7 +246,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
|
|||
result.push_back(obj);
|
||||
} else if(*st == notInBody) {
|
||||
if(ui->bodyRadioIndependent->isChecked()) {
|
||||
auto copy = makeCopy(obj, true);
|
||||
auto copy = makeCopy(obj, "", true);
|
||||
activeBody->addFeature(copy);
|
||||
// doesn't supposed to get here anything but sketch but to be on the safe side better to check
|
||||
if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
|
||||
|
@ -270,7 +270,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
|
|||
return result;
|
||||
}
|
||||
|
||||
App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool independent) {
|
||||
App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::string sub, bool independent) {
|
||||
App::DocumentObject* copy = nullptr;
|
||||
if(independent) {
|
||||
|
||||
|
@ -308,11 +308,19 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
|
|||
}
|
||||
|
||||
cprop->Paste(*prop);
|
||||
|
||||
}
|
||||
|
||||
if(!sub.empty() && copy &&
|
||||
copy->isDerivedFrom(Part::Feature::getClassTypeId()) && obj->isDerivedFrom(Part::Feature::getClassTypeId()))
|
||||
static_cast<Part::Feature*>(copy)->Shape.setValue(static_cast<Part::Feature*>(obj)->Shape.getShape().getSubShape(sub.c_str()));
|
||||
}
|
||||
else {
|
||||
|
||||
auto name = std::string("Reference") + std::string(obj->getNameInDocument());
|
||||
const char* entity = std::string("").c_str();
|
||||
if(!sub.empty())
|
||||
entity = sub.c_str();
|
||||
|
||||
// TODO Replace it with commands (2015-09-11, Fat-Zer)
|
||||
if(obj->isDerivedFrom(Part::Datum::getClassTypeId())) {
|
||||
|
@ -323,7 +331,7 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
|
|||
//datum adjust their size dependend on the part size, hence simply copying the shape is
|
||||
//not enough
|
||||
Part::Datum *datumCopy = static_cast<Part::Datum*>(copy);
|
||||
datumCopy->Support.setValue(obj, "");
|
||||
datumCopy->Support.setValue(obj, entity);
|
||||
|
||||
if(obj->getTypeId() == PartDesign::Point::getClassTypeId()) {
|
||||
datumCopy->MapMode.setValue(mm0Vertex);
|
||||
|
@ -338,13 +346,13 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
|
|||
else if(obj->isDerivedFrom(Part::Part2DObject::getClassTypeId()) ||
|
||||
obj->getTypeId() == PartDesign::ShapeBinder2D::getClassTypeId()) {
|
||||
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder2D", name.c_str());
|
||||
static_cast<PartDesign::ShapeBinder2D*>(copy)->Support.setValue(obj, "");
|
||||
static_cast<PartDesign::ShapeBinder2D*>(copy)->Support.setValue(obj, entity);
|
||||
}
|
||||
else if(obj->getTypeId() == PartDesign::ShapeBinder::getClassTypeId() ||
|
||||
obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
|
||||
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str());
|
||||
static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, "");
|
||||
static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
std::vector<App::DocumentObject*> buildFeatures();
|
||||
void showExternal(bool val);
|
||||
|
||||
static App::DocumentObject* makeCopy(App::DocumentObject* obj, std::string sub, bool independent);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onUpdate(bool);
|
||||
void onSelectionChanged(const Gui::SelectionChanges& msg);
|
||||
|
@ -76,8 +78,6 @@ private:
|
|||
std::vector<featureStatus> statuses;
|
||||
|
||||
void updateList();
|
||||
App::DocumentObject* makeCopy(App::DocumentObject*, bool independent);
|
||||
|
||||
const QString getFeatureStatusString(const featureStatus st);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user