Color already selected faces of Draft feature when adding more or removing faces

This commit is contained in:
jrheinlaender 2013-09-26 21:10:29 +02:00 committed by Stefan Tröger
parent a15fbf3db6
commit 904799d462
4 changed files with 68 additions and 8 deletions

View File

@ -137,9 +137,10 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
pcDraft->Base.setValue(base, faces);
ui->listWidgetFaces->insertItem(0, QString::fromStdString(subName));
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonFaceAdd->setChecked(false);
clearButtons(NULL);
DraftView->highlightReferences(false);
exitSelectionMode();
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
} else if ((selectionMode == faceRemove) && (subName.size() > 4 && subName.substr(0,4) == "Face")) {
@ -157,10 +158,11 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
QListWidgetItem* it = ui->listWidgetFaces->takeItem(ui->listWidgetFaces->row(*i));
delete it;
}
}
pcDraft->getDocument()->recomputeFeature(pcDraft);
ui->buttonFaceRemove->setChecked(false);
}
clearButtons(NULL);
DraftView->highlightReferences(false);
exitSelectionMode();
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
} else if ((selectionMode == plane)) {
std::vector<std::string> planes;
@ -186,13 +188,23 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}
void TaskDraftParameters::clearButtons(const QToolButton* 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().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
DraftView->highlightReferences(true);
} else {
exitSelectionMode();
}
@ -201,10 +213,12 @@ void TaskDraftParameters::onButtonFaceAdd(bool checked)
void TaskDraftParameters::onButtonFaceRemove(bool checked)
{
if (checked) {
clearButtons(ui->buttonFaceRemove);
hideObject();
selectionMode = faceRemove;
Gui::Selection().clearSelection();
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), false, true, false));
DraftView->highlightReferences(true);
} else {
exitSelectionMode();
}
@ -213,6 +227,7 @@ void TaskDraftParameters::onButtonFaceRemove(bool checked)
void TaskDraftParameters::onButtonPlane(bool checked)
{
if (checked) {
clearButtons(ui->buttonPlane);
hideObject();
selectionMode = plane;
Gui::Selection().clearSelection();
@ -225,6 +240,7 @@ void TaskDraftParameters::onButtonPlane(bool checked)
void TaskDraftParameters::onButtonLine(bool checked)
{
if (checked) {
clearButtons(ui->buttonLine);
hideObject();
selectionMode = line;
Gui::Selection().clearSelection();
@ -278,7 +294,7 @@ void TaskDraftParameters::hideObject()
if (doc != NULL && base != NULL) {
doc->setHide(DraftView->getObject()->getNameInDocument());
doc->setShow(base->getNameInDocument());
}
}
}
void TaskDraftParameters::showObject()
@ -293,6 +309,7 @@ void TaskDraftParameters::showObject()
void TaskDraftParameters::onAngleChanged(double angle)
{
clearButtons(NULL);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
pcDraft->Angle.setValue(angle);
pcDraft->getDocument()->recomputeFeature(pcDraft);
@ -304,6 +321,7 @@ const double TaskDraftParameters::getAngle(void) const
}
void TaskDraftParameters::onReversedChanged(const bool on) {
clearButtons(NULL);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DraftView->getObject());
pcDraft->Reversed.setValue(on);
pcDraft->getDocument()->recomputeFeature(pcDraft);
@ -338,6 +356,7 @@ void TaskDraftParameters::exitSelectionMode()
{
selectionMode = none;
Gui::Selection().rmvSelectionGate();
Gui::Selection().clearSelection();
showObject();
}

View File

@ -77,6 +77,9 @@ protected:
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private:
void clearButtons(const QToolButton* notThis);
private:
QWidget* proxy;
Ui_TaskDraftParameters* ui;

View File

@ -27,6 +27,8 @@
# include <QAction>
# include <QMenu>
# include <QMessageBox>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopExp.hxx>
#endif
#include "ViewProviderDraft.h"
@ -107,4 +109,34 @@ 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);
}
}

View File

@ -44,9 +44,15 @@ public:
virtual bool onDelete(const std::vector<std::string> &);
/// Highlight the faces that have been selected
void highlightReferences(const bool on);
protected:
virtual bool setEdit(int ModNum);
private:
std::vector<App::Color> originalColors;
};