Skip to content

Commit

Permalink
Part: [skip ci] simplifications in primitives location dialog
Browse files Browse the repository at this point in the history
- do not use a QSignalMapper if the slot doesn't take care of the emitting widget
- to set the placement only check for the base class GeoFeature, i.e. no need to step through all primitive types
- fix compiler warning of unused variable
  • Loading branch information
wwmayer committed Nov 10, 2020
1 parent f0af88e commit f9420c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 103 deletions.
112 changes: 13 additions & 99 deletions src/Mod/Part/Gui/DlgPrimitives.cpp
Expand Up @@ -1605,15 +1605,13 @@ Location::Location(QWidget* parent, Part::Feature* feature)
ui.AngleQSB->setValue(Base::toDegrees<double>(rotationAngle));

//connect signals
QSignalMapper* mapper = new QSignalMapper(this);
connect(mapper, SIGNAL(mapped(QWidget*)), this, SLOT(onChangePosRot(QWidget*)));
connectSignalMapper(ui.XPositionQSB, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.YPositionQSB, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.ZPositionQSB, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.AngleQSB, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.XDirectionEdit, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.YDirectionEdit, SIGNAL(valueChanged(double)), mapper);
connectSignalMapper(ui.ZDirectionEdit, SIGNAL(valueChanged(double)), mapper);
connect(ui.XPositionQSB, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.YPositionQSB, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.ZPositionQSB, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.AngleQSB, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.XDirectionEdit, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.YDirectionEdit, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
connect(ui.ZDirectionEdit, SIGNAL(valueChanged(double)), this, SLOT(onChangePosRot()));
}
}

Expand All @@ -1632,16 +1630,11 @@ Location::~Location()
}
}

void Location::connectSignalMapper(QWidget* sender, const char* signal, QSignalMapper* mapper)
void Location::onChangePosRot()
{
connect(sender, signal, mapper, SLOT(map()));
mapper->setMapping(sender, sender);
}

void Location::onChangePosRot(QWidget* widget)
{
App::Document* doc = featurePtr->getDocument();
Base::Type type = featurePtr->getTypeId();
App::GeoFeature* geom = featurePtr.get<App::GeoFeature>();
if (!geom)
return;

// read dialog values
Base::Vector3d loc;
Expand All @@ -1663,87 +1656,8 @@ void Location::onChangePosRot(QWidget* widget)
placement.setRotation(rotation);

// apply new placement to the feature

if (type == Part::Plane::getClassTypeId()) {
Part::Plane* plane = featurePtr.get<Part::Plane>();
plane->Placement.setValue(placement);
plane->recomputeFeature();
}
else if (type == Part::Box::getClassTypeId()) {
Part::Box* box = featurePtr.get<Part::Box>();
box->Placement.setValue(placement);
box->recomputeFeature();
}
else if (type == Part::Cylinder::getClassTypeId()) {
Part::Cylinder* cylinder = featurePtr.get<Part::Cylinder>();
cylinder->Placement.setValue(placement);
cylinder->recomputeFeature();
}
else if (type == Part::Cone::getClassTypeId()) {
Part::Cone* cone = featurePtr.get<Part::Cone>();
cone->Placement.setValue(placement);
cone->recomputeFeature();
}
else if (type == Part::Sphere::getClassTypeId()) {
Part::Sphere* sphere = featurePtr.get<Part::Sphere>();
sphere->Placement.setValue(placement);
sphere->recomputeFeature();
}
else if (type == Part::Ellipsoid::getClassTypeId()) {
Part::Ellipsoid* ellipsoid = featurePtr.get<Part::Ellipsoid>();
ellipsoid->Placement.setValue(placement);
ellipsoid->recomputeFeature();
}
else if (type == Part::Torus::getClassTypeId()) {
Part::Torus* torus = featurePtr.get<Part::Torus>();
torus->Placement.setValue(placement);
torus->recomputeFeature();
}
else if (type == Part::Prism::getClassTypeId()) {
Part::Prism* prism = featurePtr.get<Part::Prism>();
prism->Placement.setValue(placement);
prism->recomputeFeature();
}
else if (type == Part::Wedge::getClassTypeId()) {
Part::Wedge* wedge = featurePtr.get<Part::Wedge>();
wedge->Placement.setValue(placement);
wedge->recomputeFeature();
}
else if (type == Part::Helix::getClassTypeId()) {
Part::Helix* helix = featurePtr.get<Part::Helix>();
helix->Placement.setValue(placement);
helix->recomputeFeature();
}
else if (type == Part::Spiral::getClassTypeId()) {
Part::Spiral* spiral = featurePtr.get<Part::Spiral>();
spiral->Placement.setValue(placement);
spiral->recomputeFeature();
}
else if (type == Part::Circle::getClassTypeId()) {
Part::Circle* circle = featurePtr.get<Part::Circle>();
circle->Placement.setValue(placement);
circle->recomputeFeature();
}
else if (type == Part::Ellipse::getClassTypeId()) {
Part::Ellipse* ellipse = featurePtr.get<Part::Ellipse>();
ellipse->Placement.setValue(placement);
ellipse->recomputeFeature();
}
else if (type == Part::Vertex::getClassTypeId()) {
Part::Vertex* vertex = featurePtr.get<Part::Vertex>();
vertex->Placement.setValue(placement);
vertex->recomputeFeature();
}
else if (type == Part::Line::getClassTypeId()) {
Part::Line* line = featurePtr.get<Part::Line>();
line->Placement.setValue(placement);
line->recomputeFeature();
}
else if (type == Part::RegularPolygon::getClassTypeId()) {
Part::RegularPolygon* polygon = featurePtr.get<Part::RegularPolygon>();
polygon->Placement.setValue(placement);
polygon->recomputeFeature();
}
geom->Placement.setValue(placement);
geom->recomputeFeature();
}

void Location::on_viewPositionButton_clicked()
Expand Down
5 changes: 1 addition & 4 deletions src/Mod/Part/Gui/DlgPrimitives.h
Expand Up @@ -112,12 +112,9 @@ class Location : public QWidget
QString toPlacement() const;

private Q_SLOTS:
void onChangePosRot(QWidget*);
void onChangePosRot();
void on_viewPositionButton_clicked();

private:
void connectSignalMapper(QWidget* sender, const char* signal, QSignalMapper* mapper);

private:
static void pickCallback(void * ud, SoEventCallback * n);
int mode;
Expand Down

0 comments on commit f9420c9

Please sign in to comment.