Unify code of Dressup features (part 2: Draft)
This commit is contained in:
parent
3229b322ec
commit
8b19d2cf16
|
@ -44,99 +44,29 @@ using namespace PartDesignGui;
|
|||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProviderDressUp)
|
||||
|
||||
ViewProviderDraft::ViewProviderDraft()
|
||||
{
|
||||
sPixmap = "PartDesign_Draft.svg";
|
||||
}
|
||||
|
||||
ViewProviderDraft::~ViewProviderDraft()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ViewProviderDraft::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit draft"), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderDraft::setEdit(int ModNum)
|
||||
{
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
// When double-clicking on the item for this fillet the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
TaskDlgDraftParameters *draftDlg = qobject_cast<TaskDlgDraftParameters *>(dlg);
|
||||
if (draftDlg && draftDlg->getDressUpView() != this)
|
||||
draftDlg = 0; // another pad left open its task panel
|
||||
if (dlg && !draftDlg) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
|
||||
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
int ret = msgBox.exec();
|
||||
if (ret == QMessageBox::Yes)
|
||||
Gui::Control().reject();
|
||||
TaskDlgDressUpParameters *dressUpDlg = NULL;
|
||||
|
||||
if (checkDlgOpen(dressUpDlg)) {
|
||||
// always change to PartDesign WB, remember where we come from
|
||||
oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||
|
||||
// start the edit dialog
|
||||
if (dressUpDlg)
|
||||
Gui::Control().showDialog(dressUpDlg);
|
||||
else
|
||||
return false;
|
||||
Gui::Control().showDialog(new TaskDlgDraftParameters(this));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// clear the selection (convenience)
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
// always change to PartDesign WB, remember where we come from
|
||||
oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||
|
||||
// start the edit dialog
|
||||
if (draftDlg)
|
||||
Gui::Control().showDialog(draftDlg);
|
||||
else
|
||||
Gui::Control().showDialog(new TaskDlgDraftParameters(this));
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return PartGui::ViewProviderPart::setEdit(ModNum);
|
||||
return ViewProviderDressUp::setEdit(ModNum);
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderDraft::onDelete(const std::vector<std::string> &s)
|
||||
{
|
||||
return ViewProvider::onDelete(s);
|
||||
}
|
||||
|
||||
void ViewProviderDraft::highlightReferences(const bool on)
|
||||
{
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(getObject());
|
||||
Part::Feature* base = static_cast<Part::Feature*>(pcDraft->Base.getValue());
|
||||
if (base == NULL) return;
|
||||
PartGui::ViewProviderPart* vp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(base));
|
||||
if (vp == NULL) return;
|
||||
|
||||
if (on) {
|
||||
std::vector<std::string> SubVals = pcDraft->Base.getSubValuesStartsWith("Face");
|
||||
if (SubVals.size() == 0) return;
|
||||
|
||||
TopTools_IndexedMapOfShape fMap;
|
||||
TopExp::MapShapes(base->Shape.getValue(), TopAbs_FACE, fMap);
|
||||
|
||||
originalColors = vp->DiffuseColor.getValues();
|
||||
std::vector<App::Color> colors = originalColors;
|
||||
colors.resize(fMap.Extent(), ShapeColor.getValue());
|
||||
|
||||
for (std::vector<std::string>::const_iterator f = SubVals.begin(); f != SubVals.end(); f++) {
|
||||
int idx = atoi(f->substr(4).c_str()) - 1;
|
||||
// TODO: Find a better colour
|
||||
colors[idx] = App::Color(0.2,1,0.2);
|
||||
}
|
||||
vp->DiffuseColor.setValues(colors);
|
||||
} else {
|
||||
vp->DiffuseColor.setValues(originalColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,28 +35,14 @@ class PartDesignGuiExport ViewProviderDraft : public ViewProviderDressUp
|
|||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderDraft();
|
||||
/// destructor
|
||||
virtual ~ViewProviderDraft();
|
||||
|
||||
/// grouping handling
|
||||
void setupContextMenu(QMenu*, QObject*, const char*);
|
||||
|
||||
virtual bool onDelete(const std::vector<std::string> &);
|
||||
|
||||
/// Highlight the faces that have been selected
|
||||
void highlightReferences(const bool on);
|
||||
ViewProviderDraft()
|
||||
{ featureName = std::string("Draft");
|
||||
sPixmap = "PartDesign_Draft.svg"; }
|
||||
|
||||
protected:
|
||||
virtual bool setEdit(int ModNum);
|
||||
|
||||
private:
|
||||
std::vector<App::Color> originalColors;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace PartDesignGui
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user