Unify code of Dressup features (part 1: Draft)
This commit is contained in:
parent
6c494157f5
commit
a2359adb2e
|
@ -41,6 +41,7 @@
|
|||
#include "ViewProviderChamfer.h"
|
||||
#include "ViewProviderFillet.h"
|
||||
#include "ViewProviderDraft.h"
|
||||
#include "ViewProviderDressUp.h"
|
||||
#include "ViewProviderRevolution.h"
|
||||
#include "ViewProviderGroove.h"
|
||||
#include "ViewProviderMirrored.h"
|
||||
|
@ -48,6 +49,7 @@
|
|||
#include "ViewProviderPolarPattern.h"
|
||||
#include "ViewProviderScaled.h"
|
||||
#include "ViewProviderMultiTransform.h"
|
||||
#include "ViewProviderTransformed.h"
|
||||
#include "ViewProviderDatumPoint.h"
|
||||
#include "ViewProviderDatumLine.h"
|
||||
#include "ViewProviderDatumPlane.h"
|
||||
|
@ -114,10 +116,12 @@ PyMODINIT_FUNC initPartDesignGui()
|
|||
PartDesignGui::ViewProviderPocket ::init();
|
||||
PartDesignGui::ViewProviderPad ::init();
|
||||
PartDesignGui::ViewProviderRevolution ::init();
|
||||
PartDesignGui::ViewProviderDressUp ::init();
|
||||
PartDesignGui::ViewProviderGroove ::init();
|
||||
PartDesignGui::ViewProviderChamfer ::init();
|
||||
PartDesignGui::ViewProviderFillet ::init();
|
||||
PartDesignGui::ViewProviderDraft ::init();
|
||||
PartDesignGui::ViewProviderTransformed ::init();
|
||||
PartDesignGui::ViewProviderMirrored ::init();
|
||||
PartDesignGui::ViewProviderLinearPattern ::init();
|
||||
PartDesignGui::ViewProviderPolarPattern ::init();
|
||||
|
|
|
@ -35,6 +35,7 @@ set(PartDesignGui_MOC_HDRS
|
|||
TaskChamferParameters.h
|
||||
TaskFilletParameters.h
|
||||
TaskDraftParameters.h
|
||||
TaskDressUpParameters.h
|
||||
TaskHoleParameters.h
|
||||
TaskRevolutionParameters.h
|
||||
TaskGrooveParameters.h
|
||||
|
@ -91,6 +92,8 @@ SET(PartDesignGuiViewProvider_SRCS
|
|||
ViewProviderFillet.h
|
||||
ViewProviderDraft.cpp
|
||||
ViewProviderDraft.h
|
||||
ViewProviderDressUp.cpp
|
||||
ViewProviderDressUp.h
|
||||
ViewProviderRevolution.cpp
|
||||
ViewProviderRevolution.h
|
||||
ViewProviderGroove.cpp
|
||||
|
@ -143,6 +146,8 @@ SET(PartDesignGuiTaskDlgs_SRCS
|
|||
TaskDraftParameters.ui
|
||||
TaskDraftParameters.cpp
|
||||
TaskDraftParameters.h
|
||||
TaskDressUpParameters.cpp
|
||||
TaskDressUpParameters.h
|
||||
TaskRevolutionParameters.ui
|
||||
TaskRevolutionParameters.cpp
|
||||
TaskRevolutionParameters.h
|
||||
|
|
|
@ -43,8 +43,6 @@
|
|||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Mod/PartDesign/App/FeatureDraft.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
@ -52,11 +50,9 @@ using namespace Gui;
|
|||
|
||||
/* TRANSLATOR PartDesignGui::TaskDraftParameters */
|
||||
|
||||
TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *parent)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Draft"),tr("Draft parameters"),true, parent),DraftView(DraftView)
|
||||
TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
|
||||
: TaskDressUpParameters(DressUpView, parent)
|
||||
{
|
||||
selectionMode = none;
|
||||
|
||||
// we need a separate container widget to add all controls to
|
||||
proxy = new QWidget(this);
|
||||
ui = new Ui_TaskDraftParameters();
|
||||
|
@ -67,10 +63,10 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p
|
|||
this, SLOT(onAngleChanged(double)));
|
||||
connect(ui->checkReverse, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onReversedChanged(bool)));
|
||||
connect(ui->buttonFaceAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonFaceAdd(bool)));
|
||||
connect(ui->buttonFaceRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonFaceRemove(bool)));
|
||||
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefAdd(bool)));
|
||||
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefRemove(bool)));
|
||||
connect(ui->buttonPlane, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonPlane(bool)));
|
||||
connect(ui->buttonLine, SIGNAL(toggled(bool)),
|
||||
|
@ -78,7 +74,7 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p
|
|||
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
double a = pcDraft->Angle.getValue();
|
||||
|
||||
ui->draftAngle->setMinimum(0.0);
|
||||
|
@ -93,13 +89,13 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDraft *DraftView,QWidget *p
|
|||
std::vector<std::string> strings = pcDraft->Base.getSubValues();
|
||||
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i)
|
||||
{
|
||||
ui->listWidgetFaces->insertItem(0, QString::fromStdString(*i));
|
||||
ui->listWidgetReferences->insertItem(0, QString::fromStdString(*i));
|
||||
}
|
||||
// Create context menu
|
||||
QAction* action = new QAction(tr("Remove"), this);
|
||||
ui->listWidgetFaces->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onFaceDeleted()));
|
||||
ui->listWidgetFaces->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
ui->listWidgetReferences->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
|
||||
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
App::DocumentObject* ref = pcDraft->NeutralPlane.getValue();
|
||||
strings = pcDraft->NeutralPlane.getSubValues();
|
||||
|
@ -116,55 +112,15 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
|
||||
if (strcmp(msg.pDocName, DraftView->getObject()->getDocument()->getName()) != 0)
|
||||
return;
|
||||
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
App::DocumentObject* base = this->getBase();
|
||||
// TODO: Must we make a copy here instead of assigning to const char* ?
|
||||
const char* fname = base->getNameInDocument();
|
||||
std::string subName(msg.pSubName);
|
||||
|
||||
if ((selectionMode == faceAdd) && (subName.size() > 4 && subName.substr(0,4) == "Face")) {
|
||||
|
||||
if (strcmp(msg.pObjectName, fname) != 0)
|
||||
return;
|
||||
|
||||
std::vector<std::string> faces = pcDraft->Base.getSubValues();
|
||||
if (std::find(faces.begin(), faces.end(), subName) == faces.end()) {
|
||||
faces.push_back(subName);
|
||||
pcDraft->Base.setValue(base, faces);
|
||||
ui->listWidgetFaces->insertItem(0, QString::fromStdString(subName));
|
||||
|
||||
clearButtons(NULL);
|
||||
DraftView->highlightReferences(false);
|
||||
exitSelectionMode();
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
} else if ((selectionMode == faceRemove) && (subName.size() > 4 && subName.substr(0,4) == "Face")) {
|
||||
|
||||
if (strcmp(msg.pObjectName, fname) != 0)
|
||||
return;
|
||||
|
||||
std::vector<std::string> faces = pcDraft->Base.getSubValues();
|
||||
std::vector<std::string>::iterator f = std::find(faces.begin(), faces.end(), subName);
|
||||
if (f != faces.end()) {
|
||||
faces.erase(f);
|
||||
pcDraft->Base.setValue(base, faces);
|
||||
QList<QListWidgetItem*> items = ui->listWidgetFaces->findItems(QString::fromStdString(subName), Qt::MatchExactly);
|
||||
if (!items.empty()) {
|
||||
for (QList<QListWidgetItem*>::const_iterator i = items.begin(); i != items.end(); ++i) {
|
||||
QListWidgetItem* it = ui->listWidgetFaces->takeItem(ui->listWidgetFaces->row(*i));
|
||||
delete it;
|
||||
}
|
||||
}
|
||||
clearButtons(NULL);
|
||||
DraftView->highlightReferences(false);
|
||||
exitSelectionMode();
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
} else if ((selectionMode == plane)) {
|
||||
if (referenceSelected(msg)) {
|
||||
if (selectionMode == refAdd)
|
||||
ui->listWidgetReferences->insertItem(0, QString::fromStdString(msg.pSubName));
|
||||
else
|
||||
removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
} else if (selectionMode == plane) {
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
std::vector<std::string> planes;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcDraft, msg, selObj, planes);
|
||||
|
@ -172,9 +128,10 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|||
ui->linePlane->setText(getRefStr(selObj, planes));
|
||||
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
ui->buttonPlane->setChecked(false);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
} else if ((selectionMode == line) && (subName.size() > 4 && subName.substr(0,4) == "Edge")) {
|
||||
} else if (selectionMode == line) {
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
std::vector<std::string> edges;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcDraft, msg, selObj, edges);
|
||||
|
@ -182,90 +139,50 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|||
ui->lineLine->setText(getRefStr(selObj, edges));
|
||||
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
ui->buttonLine->setChecked(false);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::clearButtons(const QToolButton* notThis)
|
||||
void TaskDraftParameters::clearButtons(const selectionModes notThis)
|
||||
{
|
||||
if (ui->buttonFaceAdd != notThis) ui->buttonFaceAdd->setChecked(false);
|
||||
if (ui->buttonFaceRemove != notThis) ui->buttonFaceRemove->setChecked(false);
|
||||
if (ui->buttonLine != notThis) ui->buttonLine->setChecked(false);
|
||||
if (ui->buttonPlane != notThis) ui->buttonPlane->setChecked(false);
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonFaceAdd(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(ui->buttonFaceAdd);
|
||||
hideObject();
|
||||
selectionMode = faceAdd;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
|
||||
DraftView->highlightReferences(true);
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonFaceRemove(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(ui->buttonFaceRemove);
|
||||
hideObject();
|
||||
selectionMode = faceRemove;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
|
||||
DraftView->highlightReferences(true);
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
}
|
||||
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
|
||||
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
|
||||
if (notThis != line) ui->buttonLine->setChecked(false);
|
||||
if (notThis != plane) ui->buttonPlane->setChecked(false);
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonPlane(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(ui->buttonPlane);
|
||||
clearButtons(plane);
|
||||
hideObject();
|
||||
selectionMode = plane;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true));
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonLine(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(ui->buttonLine);
|
||||
clearButtons(line);
|
||||
hideObject();
|
||||
selectionMode = line;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true));
|
||||
} else {
|
||||
exitSelectionMode();
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> TaskDraftParameters::getFaces(void) const
|
||||
void TaskDraftParameters::onRefDeleted(void)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
for (int i = 0; i < ui->listWidgetFaces->count(); i++)
|
||||
result.push_back(ui->listWidgetFaces->item(i)->text().toStdString());
|
||||
return result;
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onFaceDeleted(void)
|
||||
{
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
App::DocumentObject* base = pcDraft->Base.getValue();
|
||||
std::vector<std::string> faces = pcDraft->Base.getSubValues();
|
||||
faces.erase(faces.begin() + ui->listWidgetFaces->currentRow());
|
||||
faces.erase(faces.begin() + ui->listWidgetReferences->currentRow());
|
||||
pcDraft->Base.setValue(base, faces);
|
||||
ui->listWidgetFaces->model()->removeRow(ui->listWidgetFaces->currentRow());
|
||||
ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow());
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
||||
|
@ -273,7 +190,7 @@ void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector<std::s
|
|||
{
|
||||
sub = std::vector<std::string>(1,"");
|
||||
QStringList parts = ui->linePlane->text().split(QChar::fromAscii(':'));
|
||||
obj = DraftView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
}
|
||||
|
@ -282,35 +199,15 @@ void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector<std::st
|
|||
{
|
||||
sub = std::vector<std::string>(1,"");
|
||||
QStringList parts = ui->lineLine->text().split(QChar::fromAscii(':'));
|
||||
obj = DraftView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
}
|
||||
|
||||
void TaskDraftParameters::hideObject()
|
||||
{
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
App::DocumentObject* base = getBase();
|
||||
if (doc != NULL && base != NULL) {
|
||||
doc->setHide(DraftView->getObject()->getNameInDocument());
|
||||
doc->setShow(base->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::showObject()
|
||||
{
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
App::DocumentObject* base = getBase();
|
||||
if (doc != NULL && base != NULL) {
|
||||
doc->setShow(DraftView->getObject()->getNameInDocument());
|
||||
doc->setHide(base->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onAngleChanged(double angle)
|
||||
{
|
||||
clearButtons(NULL);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
clearButtons(none);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
pcDraft->Angle.setValue(angle);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
@ -321,8 +218,8 @@ const double TaskDraftParameters::getAngle(void) const
|
|||
}
|
||||
|
||||
void TaskDraftParameters::onReversedChanged(const bool on) {
|
||||
clearButtons(NULL);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
clearButtons(none);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
pcDraft->Reversed.setValue(on);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
@ -332,12 +229,6 @@ const bool TaskDraftParameters::getReversed(void) const
|
|||
return ui->checkReverse->isChecked();
|
||||
}
|
||||
|
||||
App::DocumentObject* TaskDraftParameters::getBase(void) const
|
||||
{
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
|
||||
return pcDraft->Base.getValue();
|
||||
}
|
||||
|
||||
TaskDraftParameters::~TaskDraftParameters()
|
||||
{
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
|
@ -352,24 +243,16 @@ void TaskDraftParameters::changeEvent(QEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::exitSelectionMode()
|
||||
{
|
||||
selectionMode = none;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
Gui::Selection().clearSelection();
|
||||
showObject();
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// TaskDialog
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DraftView)
|
||||
: TaskDialog(),DraftView(DraftView)
|
||||
TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView)
|
||||
: TaskDlgDressUpParameters(DressUpView)
|
||||
{
|
||||
assert(DraftView);
|
||||
parameter = new TaskDraftParameters(DraftView);
|
||||
parameter = new TaskDraftParameters(DressUpView);
|
||||
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
|
@ -382,19 +265,14 @@ TaskDlgDraftParameters::~TaskDlgDraftParameters()
|
|||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
|
||||
void TaskDlgDraftParameters::open()
|
||||
{
|
||||
// a transaction is already open at creation time of the draft
|
||||
if (!Gui::Command::hasPendingCommand()) {
|
||||
QString msg = QObject::tr("Edit draft");
|
||||
Gui::Command::openCommand((const char*)msg.toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDlgDraftParameters::clicked(int)
|
||||
{
|
||||
|
||||
}
|
||||
//void TaskDlgDraftParameters::open()
|
||||
//{
|
||||
// // a transaction is already open at creation time of the draft
|
||||
// if (!Gui::Command::hasPendingCommand()) {
|
||||
// QString msg = QObject::tr("Edit draft");
|
||||
// Gui::Command::openCommand((const char*)msg.toUtf8());
|
||||
// }
|
||||
//}
|
||||
|
||||
bool TaskDlgDraftParameters::accept()
|
||||
{
|
||||
|
@ -403,7 +281,8 @@ bool TaskDlgDraftParameters::accept()
|
|||
// Force the user to select a neutral plane
|
||||
std::vector<std::string> strings;
|
||||
App::DocumentObject* obj;
|
||||
parameter->getPlane(obj, strings);
|
||||
TaskDraftParameters* draftparameter = static_cast<TaskDraftParameters*>(parameter);
|
||||
draftparameter->getPlane(obj, strings);
|
||||
std::string neutralPlane = getPythonStr(obj, strings);
|
||||
if (neutralPlane.empty()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"),
|
||||
|
@ -411,62 +290,22 @@ bool TaskDlgDraftParameters::accept()
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string name = DraftView->getObject()->getNameInDocument();
|
||||
std::string name = DressUpView->getObject()->getNameInDocument();
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed());
|
||||
try {
|
||||
std::vector<std::string> faces = parameter->getFaces();
|
||||
std::stringstream str;
|
||||
str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument."
|
||||
<< parameter->getBase()->getNameInDocument() << ",[";
|
||||
for (std::vector<std::string>::const_iterator it = faces.begin(); it != faces.end(); ++it)
|
||||
str << "\"" << *it << "\",";
|
||||
str << "])";
|
||||
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
|
||||
return false;
|
||||
}
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed());
|
||||
if (!neutralPlane.empty()) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str());
|
||||
} else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str());
|
||||
parameter->getLine(obj, strings);
|
||||
draftparameter->getLine(obj, strings);
|
||||
std::string pullDirection = getPythonStr(obj, strings);
|
||||
if (!pullDirection.empty()) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str());
|
||||
} else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
return true;
|
||||
return TaskDlgDressUpParameters::accept();
|
||||
}
|
||||
|
||||
bool TaskDlgDraftParameters::reject()
|
||||
{
|
||||
// roll back the done things
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||
|
||||
// Body housekeeping
|
||||
if (ActivePartObject != NULL) {
|
||||
// Make the new Tip and the previous solid feature visible again
|
||||
App::DocumentObject* tip = ActivePartObject->Tip.getValue();
|
||||
App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature();
|
||||
if (tip != NULL) {
|
||||
Gui::Application::Instance->getViewProvider(tip)->show();
|
||||
if ((tip != prev) && (prev != NULL))
|
||||
Gui::Application::Instance->getViewProvider(prev)->show();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "moc_TaskDraftParameters.cpp"
|
||||
|
|
332
src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig
Normal file
332
src/Mod/PartDesign/Gui/TaskDraftParameters.cpp.orig
Normal file
|
@ -0,0 +1,332 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "ui_TaskDraftParameters.h"
|
||||
#include "TaskDraftParameters.h"
|
||||
#include "Workbench.h"
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Mod/PartDesign/App/FeatureDraft.h>
|
||||
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||
|
||||
using namespace PartDesignGui;
|
||||
using namespace Gui;
|
||||
|
||||
/* TRANSLATOR PartDesignGui::TaskDraftParameters */
|
||||
|
||||
TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
|
||||
: TaskDressUpParameters(DressUpView, parent)
|
||||
{
|
||||
// we need a separate container widget to add all controls to
|
||||
proxy = new QWidget(this);
|
||||
ui = new Ui_TaskDraftParameters();
|
||||
ui->setupUi(proxy);
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
|
||||
connect(ui->draftAngle, SIGNAL(valueChanged(double)),
|
||||
this, SLOT(onAngleChanged(double)));
|
||||
connect(ui->checkReverse, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onReversedChanged(bool)));
|
||||
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefAdd(bool)));
|
||||
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonRefRemove(bool)));
|
||||
connect(ui->buttonPlane, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonPlane(bool)));
|
||||
connect(ui->buttonLine, SIGNAL(toggled(bool)),
|
||||
this, SLOT(onButtonLine(bool)));
|
||||
|
||||
this->groupLayout()->addWidget(proxy);
|
||||
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
double a = pcDraft->Angle.getValue();
|
||||
|
||||
ui->draftAngle->setMinimum(0.0);
|
||||
ui->draftAngle->setMaximum(89.99);
|
||||
ui->draftAngle->setValue(a);
|
||||
ui->draftAngle->selectAll();
|
||||
QMetaObject::invokeMethod(ui->draftAngle, "setFocus", Qt::QueuedConnection);
|
||||
|
||||
bool r = pcDraft->Reversed.getValue();
|
||||
ui->checkReverse->setChecked(r);
|
||||
|
||||
std::vector<std::string> strings = pcDraft->Base.getSubValues();
|
||||
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i)
|
||||
{
|
||||
ui->listWidgetReferences->insertItem(0, QString::fromStdString(*i));
|
||||
}
|
||||
// Create context menu
|
||||
QAction* action = new QAction(tr("Remove"), this);
|
||||
ui->listWidgetReferences->addAction(action);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
|
||||
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
|
||||
App::DocumentObject* ref = pcDraft->NeutralPlane.getValue();
|
||||
strings = pcDraft->NeutralPlane.getSubValues();
|
||||
ui->linePlane->setText(getRefStr(ref, strings));
|
||||
|
||||
ref = pcDraft->PullDirection.getValue();
|
||||
strings = pcDraft->PullDirection.getSubValues();
|
||||
ui->lineLine->setText(getRefStr(ref, strings));
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if (selectionMode == none)
|
||||
return;
|
||||
|
||||
if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
||||
if (referenceSelected(msg)) {
|
||||
if (selectionMode == refAdd)
|
||||
ui->listWidgetReferences->insertItem(0, QString::fromStdString(msg.pSubName));
|
||||
else
|
||||
removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
} else if (selectionMode == plane) {
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
std::vector<std::string> planes;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcDraft, msg, selObj, planes);
|
||||
pcDraft->NeutralPlane.setValue(selObj, planes);
|
||||
ui->linePlane->setText(getRefStr(selObj, planes));
|
||||
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
} else if (selectionMode == line) {
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
std::vector<std::string> edges;
|
||||
App::DocumentObject* selObj;
|
||||
getReferencedSelection(pcDraft, msg, selObj, edges);
|
||||
pcDraft->PullDirection.setValue(selObj, edges);
|
||||
ui->lineLine->setText(getRefStr(selObj, edges));
|
||||
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
clearButtons(none);
|
||||
exitSelectionMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::clearButtons(const selectionModes notThis)
|
||||
{
|
||||
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
|
||||
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
|
||||
if (notThis != line) ui->buttonLine->setChecked(false);
|
||||
if (notThis != plane) ui->buttonPlane->setChecked(false);
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonPlane(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(plane);
|
||||
hideObject();
|
||||
selectionMode = plane;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onButtonLine(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(line);
|
||||
hideObject();
|
||||
selectionMode = line;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true));
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onRefDeleted(void)
|
||||
{
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
App::DocumentObject* base = pcDraft->Base.getValue();
|
||||
std::vector<std::string> faces = pcDraft->Base.getSubValues();
|
||||
faces.erase(faces.begin() + ui->listWidgetReferences->currentRow());
|
||||
pcDraft->Base.setValue(base, faces);
|
||||
ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow());
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
||||
void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const
|
||||
{
|
||||
sub = std::vector<std::string>(1,"");
|
||||
QStringList parts = ui->linePlane->text().split(QChar::fromAscii(':'));
|
||||
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
}
|
||||
|
||||
void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector<std::string>& sub) const
|
||||
{
|
||||
sub = std::vector<std::string>(1,"");
|
||||
QStringList parts = ui->lineLine->text().split(QChar::fromAscii(':'));
|
||||
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
|
||||
if (parts.size() > 1)
|
||||
sub[0] = parts[1].toStdString();
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onAngleChanged(double angle)
|
||||
{
|
||||
clearButtons(none);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
pcDraft->Angle.setValue(angle);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
||||
const double TaskDraftParameters::getAngle(void) const
|
||||
{
|
||||
return ui->draftAngle->value().getValue();
|
||||
}
|
||||
|
||||
void TaskDraftParameters::onReversedChanged(const bool on) {
|
||||
clearButtons(none);
|
||||
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
|
||||
pcDraft->Reversed.setValue(on);
|
||||
pcDraft->getDocument()->recomputeFeature(pcDraft);
|
||||
}
|
||||
|
||||
const bool TaskDraftParameters::getReversed(void) const
|
||||
{
|
||||
return ui->checkReverse->isChecked();
|
||||
}
|
||||
|
||||
TaskDraftParameters::~TaskDraftParameters()
|
||||
{
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TaskDraftParameters::changeEvent(QEvent *e)
|
||||
{
|
||||
TaskBox::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// TaskDialog
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView)
|
||||
: TaskDlgDressUpParameters(DressUpView)
|
||||
{
|
||||
parameter = new TaskDraftParameters(DressUpView);
|
||||
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
|
||||
TaskDlgDraftParameters::~TaskDlgDraftParameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
|
||||
//void TaskDlgDraftParameters::open()
|
||||
//{
|
||||
// // a transaction is already open at creation time of the draft
|
||||
// if (!Gui::Command::hasPendingCommand()) {
|
||||
// QString msg = QObject::tr("Edit draft");
|
||||
// Gui::Command::openCommand((const char*)msg.toUtf8());
|
||||
// }
|
||||
//}
|
||||
|
||||
bool TaskDlgDraftParameters::accept()
|
||||
{
|
||||
parameter->showObject();
|
||||
|
||||
// Force the user to select a neutral plane
|
||||
std::vector<std::string> strings;
|
||||
App::DocumentObject* obj;
|
||||
TaskDraftParameters* draftparameter = static_cast<TaskDraftParameters*>(parameter);
|
||||
draftparameter->getPlane(obj, strings);
|
||||
std::string neutralPlane = getPythonStr(obj, strings);
|
||||
if (neutralPlane.empty()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"),
|
||||
QObject::tr("Please select a plane or an edge plus a pull direction"));
|
||||
return false;
|
||||
}
|
||||
|
||||
<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b
|
||||
std::string name = DraftView->getObject()->getNameInDocument();
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed());
|
||||
try {
|
||||
std::vector<std::string> faces = parameter->getFaces();
|
||||
std::stringstream str;
|
||||
str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument."
|
||||
<< parameter->getBase()->getNameInDocument() << ",[";
|
||||
for (std::vector<std::string>::const_iterator it = faces.begin(); it != faces.end(); ++it)
|
||||
str << "\"" << *it << "\",";
|
||||
str << "])";
|
||||
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
|
||||
return false;
|
||||
}
|
||||
=======
|
||||
std::string name = DressUpView->getObject()->getNameInDocument();
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed());
|
||||
>>>>>>> Unify code of Dressup features (part 1: Draft)
|
||||
if (!neutralPlane.empty()) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str());
|
||||
} else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str());
|
||||
draftparameter->getLine(obj, strings);
|
||||
std::string pullDirection = getPythonStr(obj, strings);
|
||||
if (!pullDirection.empty()) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str());
|
||||
} else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str());
|
||||
|
||||
return TaskDlgDressUpParameters::accept();
|
||||
}
|
||||
|
||||
#include "moc_TaskDraftParameters.cpp"
|
|
@ -24,31 +24,19 @@
|
|||
#ifndef GUI_TASKVIEW_TaskDraftParameters_H
|
||||
#define GUI_TASKVIEW_TaskDraftParameters_H
|
||||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#include "TaskDressUpParameters.h"
|
||||
#include "ViewProviderDraft.h"
|
||||
|
||||
class Ui_TaskDraftParameters;
|
||||
|
||||
namespace App {
|
||||
class Property;
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
class ViewProvider;
|
||||
}
|
||||
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class TaskDraftParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
|
||||
class TaskDraftParameters : public TaskDressUpParameters
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDraftParameters(ViewProviderDraft *DraftView, QWidget *parent=0);
|
||||
TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
|
||||
~TaskDraftParameters();
|
||||
|
||||
const double getAngle(void) const;
|
||||
|
@ -56,41 +44,25 @@ public:
|
|||
const std::vector<std::string> getFaces(void) const;
|
||||
void getPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
|
||||
void getLine(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
|
||||
App::DocumentObject *getBase(void) const;
|
||||
|
||||
void hideObject();
|
||||
void showObject();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAngleChanged(double angle);
|
||||
void onReversedChanged(bool reversed);
|
||||
void onButtonFaceAdd(const bool checked);
|
||||
void onButtonFaceRemove(const bool checked);
|
||||
void onButtonPlane(const bool checked);
|
||||
void onButtonLine(const bool checked);
|
||||
void onFaceDeleted(void);
|
||||
|
||||
protected:
|
||||
void exitSelectionMode();
|
||||
void onRefDeleted(void);
|
||||
|
||||
protected:
|
||||
virtual void clearButtons(const selectionModes notThis);
|
||||
void changeEvent(QEvent *e);
|
||||
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
|
||||
|
||||
private:
|
||||
void clearButtons(const QToolButton* notThis);
|
||||
|
||||
private:
|
||||
QWidget* proxy;
|
||||
Ui_TaskDraftParameters* ui;
|
||||
ViewProviderDraft *DraftView;
|
||||
|
||||
enum selectionModes { none, faceAdd, faceRemove, plane, line };
|
||||
selectionModes selectionMode;
|
||||
};
|
||||
|
||||
/// simulation dialog for the TaskView
|
||||
class TaskDlgDraftParameters : public Gui::TaskView::TaskDialog
|
||||
class TaskDlgDraftParameters : public TaskDlgDressUpParameters
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -98,30 +70,9 @@ public:
|
|||
TaskDlgDraftParameters(ViewProviderDraft *DraftView);
|
||||
~TaskDlgDraftParameters();
|
||||
|
||||
ViewProviderDraft* getDraftView() const
|
||||
{ return DraftView; }
|
||||
|
||||
|
||||
public:
|
||||
/// is called the TaskView when the dialog is opened
|
||||
virtual void open();
|
||||
/// is called by the framework if an button is clicked which has no accept or reject role
|
||||
virtual void clicked(int);
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
/// is called by the framework if the dialog is rejected (Cancel)
|
||||
virtual bool reject();
|
||||
virtual bool isAllowedAlterDocument(void) const
|
||||
{ return false; }
|
||||
|
||||
/// returns for Close and Help button
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
|
||||
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
|
||||
|
||||
protected:
|
||||
ViewProviderDraft *DraftView;
|
||||
|
||||
TaskDraftParameters *parameter;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
|
96
src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig
Normal file
96
src/Mod/PartDesign/Gui/TaskDraftParameters.h.orig
Normal file
|
@ -0,0 +1,96 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef GUI_TASKVIEW_TaskDraftParameters_H
|
||||
#define GUI_TASKVIEW_TaskDraftParameters_H
|
||||
|
||||
#include "TaskDressUpParameters.h"
|
||||
#include "ViewProviderDraft.h"
|
||||
|
||||
class Ui_TaskDraftParameters;
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class TaskDraftParameters : public TaskDressUpParameters
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
|
||||
~TaskDraftParameters();
|
||||
|
||||
const double getAngle(void) const;
|
||||
const bool getReversed(void) const;
|
||||
const std::vector<std::string> getFaces(void) const;
|
||||
void getPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
|
||||
void getLine(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAngleChanged(double angle);
|
||||
void onReversedChanged(bool reversed);
|
||||
void onButtonPlane(const bool checked);
|
||||
void onButtonLine(const bool checked);
|
||||
void onRefDeleted(void);
|
||||
|
||||
protected:
|
||||
virtual void clearButtons(const selectionModes notThis);
|
||||
void changeEvent(QEvent *e);
|
||||
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
|
||||
|
||||
private:
|
||||
Ui_TaskDraftParameters* ui;
|
||||
};
|
||||
|
||||
/// simulation dialog for the TaskView
|
||||
class TaskDlgDraftParameters : public TaskDlgDressUpParameters
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDlgDraftParameters(ViewProviderDraft *DraftView);
|
||||
~TaskDlgDraftParameters();
|
||||
|
||||
public:
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b
|
||||
/// is called by the framework if the dialog is rejected (Cancel)
|
||||
virtual bool reject();
|
||||
virtual bool isAllowedAlterDocument(void) const
|
||||
{ return false; }
|
||||
|
||||
/// returns for Close and Help button
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
|
||||
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
|
||||
|
||||
protected:
|
||||
ViewProviderDraft *DraftView;
|
||||
|
||||
TaskDraftParameters *parameter;
|
||||
=======
|
||||
>>>>>>> Unify code of Dressup features (part 1: Draft)
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
||||
#endif // GUI_TASKVIEW_TASKAPPERANCE_H
|
|
@ -17,7 +17,7 @@
|
|||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonFaceAdd">
|
||||
<widget class="QToolButton" name="buttonRefAdd">
|
||||
<property name="text">
|
||||
<string>Add face</string>
|
||||
</property>
|
||||
|
@ -27,7 +27,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonFaceRemove">
|
||||
<widget class="QToolButton" name="buttonRefRemove">
|
||||
<property name="text">
|
||||
<string>Remove face</string>
|
||||
</property>
|
||||
|
@ -39,7 +39,7 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidgetFaces"/>
|
||||
<widget class="QListWidget" name="listWidgetReferences"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
|
@ -114,7 +114,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
<zorder>checkReverse</zorder>
|
||||
<zorder>listWidgetFaces</zorder>
|
||||
<zorder>listWidgetReferences</zorder>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
252
src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp
Normal file
252
src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp
Normal file
|
@ -0,0 +1,252 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QListWidgetItem>
|
||||
# include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "TaskDressUpParameters.h"
|
||||
#include "Workbench.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Mod/PartDesign/App/FeatureDressUp.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||
|
||||
using namespace PartDesignGui;
|
||||
using namespace Gui;
|
||||
|
||||
/* TRANSLATOR PartDesignGui::TaskDressUpParameters */
|
||||
|
||||
TaskDressUpParameters::TaskDressUpParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap((std::string("PartDesign_") + DressUpView->featureName).c_str()),
|
||||
QString::fromAscii((DressUpView->featureName + " parameters").c_str()),
|
||||
true,
|
||||
parent),
|
||||
DressUpView(DressUpView)
|
||||
{
|
||||
selectionMode = none;
|
||||
}
|
||||
|
||||
TaskDressUpParameters::~TaskDressUpParameters()
|
||||
{
|
||||
// make sure to remove selection gate in all cases
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
}
|
||||
|
||||
const bool TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg)
|
||||
{
|
||||
if ((msg.Type == Gui::SelectionChanges::AddSelection) && (
|
||||
(selectionMode == refAdd) || (selectionMode == refRemove))) {
|
||||
|
||||
if (strcmp(msg.pDocName, DressUpView->getObject()->getDocument()->getName()) != 0)
|
||||
return false;
|
||||
|
||||
PartDesign::DressUp* pcDressUp = static_cast<PartDesign::DressUp*>(DressUpView->getObject());
|
||||
App::DocumentObject* base = this->getBase();
|
||||
// TODO: Must we make a copy here instead of assigning to const char* ?
|
||||
const char* fname = base->getNameInDocument();
|
||||
if (strcmp(msg.pObjectName, fname) != 0)
|
||||
return false;
|
||||
|
||||
std::string subName(msg.pSubName);
|
||||
std::vector<std::string> refs = pcDressUp->Base.getSubValues();
|
||||
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
|
||||
|
||||
if (selectionMode == refAdd) {
|
||||
if (f == refs.end())
|
||||
refs.push_back(subName);
|
||||
else
|
||||
return false; // duplicate selection
|
||||
} else {
|
||||
if (f != refs.end())
|
||||
refs.erase(f);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
pcDressUp->Base.setValue(base, refs);
|
||||
DressUpView->highlightReferences(false);
|
||||
pcDressUp->getDocument()->recomputeFeature(pcDressUp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::onButtonRefAdd(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(refAdd);
|
||||
hideObject();
|
||||
selectionMode = refAdd;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
|
||||
DressUpView->highlightReferences(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::onButtonRefRemove(const bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
clearButtons(refRemove);
|
||||
hideObject();
|
||||
selectionMode = refRemove;
|
||||
Gui::Selection().clearSelection();
|
||||
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
|
||||
DressUpView->highlightReferences(true);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> TaskDressUpParameters::getReferences() const
|
||||
{
|
||||
PartDesign::DressUp* pcDressUp = static_cast<PartDesign::DressUp*>(DressUpView->getObject());
|
||||
std::vector<std::string> result = pcDressUp->Base.getSubValues();
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: This code is identical with TaskTransformedParameters::removeItemFromListWidget()
|
||||
void TaskDressUpParameters::removeItemFromListWidget(QListWidget* widget, const char* itemstr)
|
||||
{
|
||||
QList<QListWidgetItem*> items = widget->findItems(QString::fromAscii(itemstr), Qt::MatchExactly);
|
||||
if (!items.empty()) {
|
||||
for (QList<QListWidgetItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
|
||||
QListWidgetItem* it = widget->takeItem(widget->row(*i));
|
||||
delete it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::hideObject()
|
||||
{
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
App::DocumentObject* base = getBase();
|
||||
if (doc != NULL && base != NULL) {
|
||||
doc->setHide(DressUpView->getObject()->getNameInDocument());
|
||||
doc->setShow(base->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::showObject()
|
||||
{
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
App::DocumentObject* base = getBase();
|
||||
if (doc != NULL && base != NULL) {
|
||||
doc->setShow(DressUpView->getObject()->getNameInDocument());
|
||||
doc->setHide(base->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
App::DocumentObject* TaskDressUpParameters::getBase(void) const
|
||||
{
|
||||
PartDesign::DressUp* pcDressUp = static_cast<PartDesign::DressUp*>(DressUpView->getObject());
|
||||
return pcDressUp->Base.getValue();
|
||||
}
|
||||
|
||||
void TaskDressUpParameters::exitSelectionMode()
|
||||
{
|
||||
selectionMode = none;
|
||||
Gui::Selection().rmvSelectionGate();
|
||||
Gui::Selection().clearSelection();
|
||||
showObject();
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// TaskDialog
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
TaskDlgDressUpParameters::TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView)
|
||||
: TaskDialog(),DressUpView(DressUpView)
|
||||
{
|
||||
assert(DressUpView);
|
||||
}
|
||||
|
||||
TaskDlgDressUpParameters::~TaskDlgDressUpParameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
bool TaskDlgDressUpParameters::accept()
|
||||
{
|
||||
std::string name = DressUpView->getObject()->getNameInDocument();
|
||||
|
||||
try {
|
||||
std::vector<std::string> refs = parameter->getReferences();
|
||||
std::stringstream str;
|
||||
str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument."
|
||||
<< parameter->getBase()->getNameInDocument() << ",[";
|
||||
for (std::vector<std::string>::const_iterator it = refs.begin(); it != refs.end(); ++it)
|
||||
str << "\"" << *it << "\",";
|
||||
str << "])";
|
||||
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));
|
||||
return false;
|
||||
}
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskDlgDressUpParameters::reject()
|
||||
{
|
||||
// roll back the done things
|
||||
Gui::Command::abortCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||
|
||||
// Body housekeeping
|
||||
if (ActivePartObject != NULL) {
|
||||
// Make the new Tip and the previous solid feature visible again
|
||||
App::DocumentObject* tip = ActivePartObject->Tip.getValue();
|
||||
App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature();
|
||||
if (tip != NULL) {
|
||||
Gui::Application::Instance->getViewProvider(tip)->show();
|
||||
if ((tip != prev) && (prev != NULL))
|
||||
Gui::Application::Instance->getViewProvider(prev)->show();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "moc_TaskDressUpParameters.cpp"
|
112
src/Mod/PartDesign/Gui/TaskDressUpParameters.h
Normal file
112
src/Mod/PartDesign/Gui/TaskDressUpParameters.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef GUI_TASKVIEW_TaskDressUpParameters_H
|
||||
#define GUI_TASKVIEW_TaskDressUpParameters_H
|
||||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#include "ViewProviderDressUp.h"
|
||||
|
||||
class QListWidget;
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class TaskDressUpParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDressUpParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
|
||||
virtual ~TaskDressUpParameters();
|
||||
|
||||
const std::vector<std::string> getReferences(void) const;
|
||||
App::DocumentObject *getBase(void) const;
|
||||
|
||||
void hideObject();
|
||||
void showObject();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onButtonRefAdd(const bool checked);
|
||||
void onButtonRefRemove(const bool checked);
|
||||
virtual void onRefDeleted(void)=0;
|
||||
|
||||
protected:
|
||||
void exitSelectionMode();
|
||||
const bool referenceSelected(const Gui::SelectionChanges& msg);
|
||||
|
||||
protected:
|
||||
enum selectionModes { none, refAdd, refRemove, plane, line };
|
||||
virtual void clearButtons(const selectionModes notThis) = 0;
|
||||
virtual void changeEvent(QEvent *e) = 0;
|
||||
static void removeItemFromListWidget(QListWidget* widget, const char* itemstr);
|
||||
|
||||
protected:
|
||||
QWidget* proxy;
|
||||
ViewProviderDressUp *DressUpView;
|
||||
|
||||
|
||||
selectionModes selectionMode;
|
||||
};
|
||||
|
||||
/// simulation dialog for the TaskView
|
||||
class TaskDlgDressUpParameters : public Gui::TaskView::TaskDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView);
|
||||
virtual ~TaskDlgDressUpParameters();
|
||||
|
||||
ViewProviderDressUp* getDressUpView() const
|
||||
{ return DressUpView; }
|
||||
|
||||
|
||||
public:
|
||||
/// is called the TaskView when the dialog is opened
|
||||
virtual void open() {}
|
||||
/// is called by the framework if an button is clicked which has no accept or reject role
|
||||
virtual void clicked(int) {}
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
/// is called by the framework if the dialog is rejected (Cancel)
|
||||
virtual bool reject();
|
||||
/// is called by the framework if the user presses the help button
|
||||
virtual bool isAllowedAlterDocument(void) const
|
||||
{ return false; }
|
||||
|
||||
/// returns for Close and Help button
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
|
||||
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
|
||||
|
||||
protected:
|
||||
ViewProviderDressUp *DressUpView;
|
||||
|
||||
TaskDressUpParameters *parameter;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
||||
#endif // GUI_TASKVIEW_TaskDressUpParameters_H
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProvider)
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDraft,PartDesignGui::ViewProviderDressUp)
|
||||
|
||||
ViewProviderDraft::ViewProviderDraft()
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ bool ViewProviderDraft::setEdit(int ModNum)
|
|||
// the task panel
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
TaskDlgDraftParameters *draftDlg = qobject_cast<TaskDlgDraftParameters *>(dlg);
|
||||
if (draftDlg && draftDlg->getDraftView() != this)
|
||||
if (draftDlg && draftDlg->getDressUpView() != this)
|
||||
draftDlg = 0; // another pad left open its task panel
|
||||
if (dlg && !draftDlg) {
|
||||
QMessageBox msgBox;
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
#ifndef PARTGUI_ViewProviderDraft_H
|
||||
#define PARTGUI_ViewProviderDraft_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include "ViewProviderDressUp.h"
|
||||
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class PartDesignGuiExport ViewProviderDraft : public ViewProvider
|
||||
class PartDesignGuiExport ViewProviderDraft : public ViewProviderDressUp
|
||||
{
|
||||
PROPERTY_HEADER(PartDesignGui::ViewProviderDraft);
|
||||
|
||||
|
|
121
src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp
Normal file
121
src/Mod/PartDesign/Gui/ViewProviderDressUp.cpp
Normal file
|
@ -0,0 +1,121 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QVariant>
|
||||
# include <QMenu>
|
||||
# include <QAction>
|
||||
# include <QMessageBox>
|
||||
# include <TopTools_IndexedMapOfShape.hxx>
|
||||
# include <TopExp.hxx>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderDressUp.h"
|
||||
#include "TaskDressUpParameters.h"
|
||||
#include <Mod/PartDesign/App/FeatureDressUp.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Application.h>
|
||||
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDressUp,PartDesignGui::ViewProvider)
|
||||
|
||||
void ViewProviderDressUp::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr((std::string("Edit ") + featureName + " feature").c_str()), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
const bool ViewProviderDressUp::checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg) {
|
||||
// When double-clicking on the item for this feature the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
dressUpDlg = qobject_cast<TaskDlgDressUpParameters *>(dlg);
|
||||
|
||||
if ((dressUpDlg != NULL) && (dressUpDlg->getDressUpView() != this))
|
||||
dressUpDlg = NULL; // another transformed feature left open its task panel
|
||||
|
||||
if ((dlg != NULL) && (dressUpDlg == NULL)) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
|
||||
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
int ret = msgBox.exec();
|
||||
if (ret == QMessageBox::Yes)
|
||||
Gui::Control().closeDialog();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// clear the selection (convenience)
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
// Continue (usually in virtual method setEdit())
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderDressUp::onDelete(const std::vector<std::string> &s)
|
||||
{
|
||||
return ViewProvider::onDelete(s);
|
||||
}
|
||||
|
||||
void ViewProviderDressUp::highlightReferences(const bool on)
|
||||
{
|
||||
PartDesign::DressUp* pcDressUp = static_cast<PartDesign::DressUp*>(getObject());
|
||||
Part::Feature* base = static_cast<Part::Feature*>(pcDressUp->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 = pcDressUp->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);
|
||||
}
|
||||
}
|
||||
|
70
src/Mod/PartDesign/Gui/ViewProviderDressUp.h
Normal file
70
src/Mod/PartDesign/Gui/ViewProviderDressUp.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef PARTGUI_ViewProviderDressUp_H
|
||||
#define PARTGUI_ViewProviderDressUp_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
class TaskDlgDressUpParameters;
|
||||
|
||||
class PartDesignGuiExport ViewProviderDressUp : public ViewProvider
|
||||
{
|
||||
PROPERTY_HEADER(PartDesignGui::ViewProviderDressUp);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderDressUp()
|
||||
: featureName("undefined") {}
|
||||
/// destructor
|
||||
virtual ~ViewProviderDressUp()
|
||||
{}
|
||||
|
||||
/// grouping handling
|
||||
void setupContextMenu(QMenu*, QObject*, const char*);
|
||||
|
||||
virtual bool onDelete(const std::vector<std::string> &);
|
||||
|
||||
/// Highlight the references that have been selected
|
||||
void highlightReferences(const bool on);
|
||||
|
||||
// The feature name of the subclass
|
||||
std::string featureName;
|
||||
|
||||
protected:
|
||||
const bool checkDlgOpen(TaskDlgDressUpParameters* dressUpDlg);
|
||||
|
||||
private:
|
||||
std::vector<App::Color> originalColors;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace PartDesignGui
|
||||
|
||||
|
||||
#endif // PARTGUI_ViewProviderDressUp_H
|
Loading…
Reference in New Issue
Block a user