Skip to content

Commit

Permalink
Sketcher: Rendering order widget
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Apr 17, 2017
1 parent 4c3ffb5 commit 937c617
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 43 deletions.
50 changes: 50 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.cpp
Expand Up @@ -54,6 +54,8 @@ SketcherGeneralWidget::SketcherGeneralWidget(QWidget *parent)
this, SLOT(setGridSize(double)));
connect(ui->checkBoxAutoconstraints, SIGNAL(stateChanged(int)),
this, SIGNAL(emitToggleAutoconstraints(int)));
connect(ui->renderingOrder->model(), SIGNAL(layoutChanged()),
this, SLOT(renderOrderChanged()));
}

SketcherGeneralWidget::~SketcherGeneralWidget()
Expand All @@ -71,6 +73,8 @@ void SketcherGeneralWidget::saveSettings()

hGrp->SetBool("GridSnap", ui->checkBoxGridSnap->isChecked());
hGrp->SetBool("AutoConstraints", ui->checkBoxAutoconstraints->isChecked());

//not necessary to save renderOrder, as it is already stored in renderOrderChanged on every change.
}

void SketcherGeneralWidget::loadSettings()
Expand All @@ -82,6 +86,28 @@ void SketcherGeneralWidget::loadSettings()
ui->gridSize->setToLastUsedValue();
ui->checkBoxGridSnap->setChecked(hGrp->GetBool("GridSnap", ui->checkBoxGridSnap->isChecked()));
ui->checkBoxAutoconstraints->setChecked(hGrp->GetBool("AutoConstraints", ui->checkBoxAutoconstraints->isChecked()));

ParameterGrp::handle hGrpp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");

// 1->Normal Geometry, 2->Construction, 3->External
int topid = hGrpp->GetInt("TopRenderGeometryId",1);
int midid = hGrpp->GetInt("MidRenderGeometryId",2);
int lowid = hGrpp->GetInt("LowRenderGeometryId",3);

QListWidgetItem *newItem = new QListWidgetItem;
newItem->setData(Qt::UserRole, QVariant(topid));
newItem->setText( topid==1?tr("Normal Geometry"):topid==2?tr("Construction Geometry"):tr("External Geometry"));
ui->renderingOrder->insertItem(0,newItem);

newItem = new QListWidgetItem;
newItem->setData(Qt::UserRole, QVariant(midid));
newItem->setText(midid==1?tr("Normal Geometry"):midid==2?tr("Construction Geometry"):tr("External Geometry"));
ui->renderingOrder->insertItem(1,newItem);

newItem = new QListWidgetItem;
newItem->setData(Qt::UserRole, QVariant(lowid));
newItem->setText(lowid==1?tr("Normal Geometry"):lowid==2?tr("Construction Geometry"):tr("External Geometry"));
ui->renderingOrder->insertItem(2,newItem);
}

void SketcherGeneralWidget::toggleGridView(bool on)
Expand Down Expand Up @@ -115,6 +141,20 @@ void SketcherGeneralWidget::changeEvent(QEvent *e)
}
}

void SketcherGeneralWidget::renderOrderChanged()
{
int topid = ui->renderingOrder->item(0)->data(Qt::UserRole).toInt();
int midid = ui->renderingOrder->item(1)->data(Qt::UserRole).toInt();
int lowid = ui->renderingOrder->item(2)->data(Qt::UserRole).toInt();

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
hGrp->SetInt("TopRenderGeometryId",topid);
hGrp->SetInt("MidRenderGeometryId",midid);
hGrp->SetInt("LowRenderGeometryId",lowid);

emitrenderOrderChanged();
}

// ----------------------------------------------------------------------------

TaskSketcherGeneral::TaskSketcherGeneral(ViewProviderSketch *sketchView)
Expand Down Expand Up @@ -145,6 +185,11 @@ TaskSketcherGeneral::TaskSketcherGeneral(ViewProviderSketch *sketchView)
this , SLOT (toggleAutoconstraints(int))
);

QObject::connect(
widget, SIGNAL(emitrenderOrderChanged()),
this , SLOT (renderOrderChanged())
);


Gui::Selection().Attach(this);
widget->loadSettings();
Expand Down Expand Up @@ -192,4 +237,9 @@ void TaskSketcherGeneral::OnChange(Gui::SelectionSingleton::SubjectType &rCaller
}
/// @endcond DOXERR

void TaskSketcherGeneral::renderOrderChanged()
{
sketchView->updateColor();
}

#include "moc_TaskSketcherGeneral.cpp"
3 changes: 3 additions & 0 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.h
Expand Up @@ -55,11 +55,13 @@ class SketcherGeneralWidget : public QWidget
void emitToggleGridSnap(int);
void emitSetGridSize(double);
void emitToggleAutoconstraints(int);
void emitrenderOrderChanged();

public Q_SLOTS:
void toggleGridView(bool on);
void setGridSize(double val);
void toggleGridSnap(int state);
void renderOrderChanged();

protected:
void changeEvent(QEvent *e);
Expand Down Expand Up @@ -88,6 +90,7 @@ public Q_SLOTS:
void setGridSize(double val);
void toggleGridSnap(int state);
void toggleAutoconstraints(int state);
void renderOrderChanged();

private:
ViewProviderSketch *sketchView;
Expand Down
81 changes: 50 additions & 31 deletions src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>153</width>
<height>115</height>
<width>194</width>
<height>228</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -34,26 +34,26 @@
</widget>
</item>
<item>
<widget class="Gui::PrefQuantitySpinBox" name="gridSize">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="maximum" stdset="0">
<double>99999999.0</double>
</property>
<property name="minimum" stdset="0">
<double>0.001</double>
</property>
<property name="singleStep" stdset="0">
<double>1.000000000000000</double>
</property>
<property name="value" stdset="0">
<double>0.0000001</double>
</property>
</widget>
<widget class="Gui::PrefQuantitySpinBox" name="gridSize" native="true">
<property name="unit" stdset="0">
<string notr="true">mm</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="maximum" stdset="0">
<double>99999999.000000000000000</double>
</property>
<property name="minimum" stdset="0">
<double>0.001000000000000</double>
</property>
<property name="singleStep" stdset="0">
<double>1.000000000000000</double>
</property>
<property name="value" stdset="0">
<double>0.000000100000000</double>
</property>
</widget>
</item>
</layout>
</item>
Expand All @@ -80,16 +80,35 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Rendering order:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="renderingOrder">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::PrefQuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<customwidgets>
<customwidget>
<class>Gui::PrefQuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>

<connections/>
<connections/>
</ui>
37 changes: 26 additions & 11 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -296,14 +296,18 @@ ViewProviderSketch::ViewProviderSketch()
PointSize.setValue(4);

zCross=0.001f;
zLines=0.005f;
zConstr=0.007f; // constraint not construction
zHighLine=0.006f;
zPoints=0.008f;
zHighlight=0.009f;
zText=0.011f;
zEdit=0.001f;
zInfo=0.004f;
zLowLines=0.005f;
//zLines=0.005f; // ZLines removed in favour of 3 height groups intended for NormalLines, ConstructionLines, ExternalLines
zMidLines=0.006f;
zHighLines=0.007f; // Lines that are somehow selected to be in the high position (higher than other line categories)
zHighLine=0.008f; // highlighted line (of any group)
zConstr=0.009f; // constraint not construction
zPoints=0.010f;
zHighlight=0.011f;
zText=0.011f;


xInit=0;
yInit=0;
Expand Down Expand Up @@ -2453,6 +2457,17 @@ void ViewProviderSketch::updateColor(void)
//int intGeoCount = getSketchObject()->getHighestCurveIndex() + 1;
//int extGeoCount = getSketchObject()->getExternalGeometryCount();

ParameterGrp::handle hGrpp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");

// 1->Normal Geometry, 2->Construction, 3->External
int topid = hGrpp->GetInt("TopRenderGeometryId",1);
int midid = hGrpp->GetInt("MidRenderGeometryId",2);
int lowid = hGrpp->GetInt("LowRenderGeometryId",3);

float zNormLine = (topid==1?zHighLines:midid==1?zMidLines:zLowLines);
float zConstrLine = (topid==2?zHighLines:midid==2?zMidLines:zLowLines);
float zExtLine = (topid==3?zHighLines:midid==3?zMidLines:zLowLines);

float x,y,z;

int j=0; // vertexindex
Expand Down Expand Up @@ -2491,28 +2506,28 @@ void ViewProviderSketch::updateColor(void)
color[i] = CurveExternalColor;
for (int k=j; j<k+indexes; j++) {
verts[j].getValue(x,y,z);
verts[j] = SbVec3f(x,y,zConstr);
verts[j] = SbVec3f(x,y,zExtLine);
}
}
else if (getSketchObject()->getGeometry(GeoId)->Construction) {
color[i] = CurveDraftColor;
for (int k=j; j<k+indexes; j++) {
verts[j].getValue(x,y,z);
verts[j] = SbVec3f(x,y,zLines);
verts[j] = SbVec3f(x,y,zConstrLine);
}
}
else if (edit->FullyConstrained) {
color[i] = FullyConstrainedColor;
for (int k=j; j<k+indexes; j++) {
verts[j].getValue(x,y,z);
verts[j] = SbVec3f(x,y,zLines);
verts[j] = SbVec3f(x,y,zLowLines);
}
}
else {
color[i] = CurveColor;
for (int k=j; j<k+indexes; j++) {
verts[j].getValue(x,y,z);
verts[j] = SbVec3f(x,y,zLines);
verts[j] = SbVec3f(x,y,zNormLine);
}
}
}
Expand Down Expand Up @@ -3874,7 +3889,7 @@ void ViewProviderSketch::draw(bool temp /*=false*/, bool rebuildinformationlayer

int i=0; // setting up the line set
for (std::vector<Base::Vector3d>::const_iterator it = Coords.begin(); it != Coords.end(); ++it,i++)
verts[i].setValue(it->x,it->y,zLines);
verts[i].setValue(it->x,it->y,zLowLines);

i=0; // setting up the indexes of the line set
for (std::vector<unsigned int>::const_iterator it = Index.begin(); it != Index.end(); ++it,i++)
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Sketcher/Gui/ViewProviderSketch.h
Expand Up @@ -386,14 +386,17 @@ class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjec
static SbVec2s newCursorPos;

float zCross;
float zLines;
//float zLines;
float zPoints;
float zConstr;
float zHighlight;
float zText;
float zEdit;
float zHighLine;
float zInfo;
float zLowLines;
float zMidLines;
float zHighLines;

// reference coordinates for relative operations
double xInit,yInit;
Expand Down

0 comments on commit 937c617

Please sign in to comment.