Skip to content

Commit

Permalink
replace hard coded numbers with static constants
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 23, 2016
1 parent d259aa0 commit 222e9b6
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 74 deletions.
22 changes: 11 additions & 11 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -52,7 +52,7 @@
# include <Standard_Version.hxx>
# include <cmath>
# include <vector>
#endif // #ifndef _PreComp_
#endif

#include <boost/bind.hpp>

Expand All @@ -72,8 +72,8 @@
#include <Mod/Part/App/BodyBase.h>

#include "SketchObject.h"
#include "SketchObjectPy.h"
#include "Sketch.h"
#include <Mod/Sketcher/App/SketchObjectPy.h>

using namespace Sketcher;
using namespace Base;
Expand Down Expand Up @@ -760,8 +760,8 @@ int SketchObject::delConstraintOnPoint(int VertexId, bool onlyCoincident)
{
int GeoId;
PointPos PosId;
if (VertexId == -1) { // RootPoint
GeoId = -1;
if (VertexId == GeoEnum::RtPnt) { // RootPoint
GeoId = Sketcher::GeoEnum::RtPnt;
PosId = start;
} else
getGeoVertexIndex(VertexId, GeoId, PosId);
Expand Down Expand Up @@ -2839,7 +2839,7 @@ int SketchObject::delExternal(int ExtGeoId)

const std::vector< Constraint * > &constraints = Constraints.getValues();
std::vector< Constraint * > newConstraints(0);
int GeoId = -3 - ExtGeoId;
int GeoId = GeoEnum::RefExt - ExtGeoId;
for (std::vector<Constraint *>::const_iterator it = constraints.begin();
it != constraints.end(); ++it) {
if ((*it)->First != GeoId && (*it)->Second != GeoId && (*it)->Third != GeoId) {
Expand Down Expand Up @@ -2893,9 +2893,9 @@ int SketchObject::delAllExternal()
std::vector< Constraint * > newConstraints(0);

for (std::vector<Constraint *>::const_iterator it = constraints.begin(); it != constraints.end(); ++it) {
if ((*it)->First > -3 &&
((*it)->Second > -3 || (*it)->Second == Constraint::GeoUndef ) &&
((*it)->Third > -3 || (*it)->Third == Constraint::GeoUndef) ) {
if ((*it)->First > GeoEnum::RefExt &&
((*it)->Second > GeoEnum::RefExt || (*it)->Second == Constraint::GeoUndef ) &&
((*it)->Third > GeoEnum::RefExt || (*it)->Third == Constraint::GeoUndef) ) {
Constraint *copiedConstr = (*it)->clone();

newConstraints.push_back(copiedConstr);
Expand Down Expand Up @@ -2924,7 +2924,7 @@ int SketchObject::delConstraintsToExternal()
{
const std::vector< Constraint * > &constraints = Constraints.getValuesForce();
std::vector< Constraint * > newConstraints(0);
int GeoId = -3, NullId = -2000;
int GeoId = GeoEnum::RefExt, NullId = Constraint::GeoUndef;
for (std::vector<Constraint *>::const_iterator it = constraints.begin();
it != constraints.end(); ++it) {
if ( (*it)->First > GeoId
Expand Down Expand Up @@ -3042,7 +3042,7 @@ void SketchObject::validateExternalLinks(void)

const std::vector< Constraint * > &constraints = Constraints.getValues();
std::vector< Constraint * > newConstraints(0);
int GeoId = -3 - i;
int GeoId = GeoEnum::RefExt - i;
for (std::vector<Constraint *>::const_iterator it = constraints.begin();
it != constraints.end(); ++it) {
if ((*it)->First != GeoId && (*it)->Second != GeoId && (*it)->Third != GeoId) {
Expand Down Expand Up @@ -4085,7 +4085,7 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze)
case 3: geoId=newVals[ic]->Third; posId = newVals[ic]->ThirdPos; break;
}

if ( geoId <= -3 &&
if ( geoId <= GeoEnum::RefExt &&
(posId==Sketcher::start || posId==Sketcher::end)){
//we are dealing with a link to an endpoint of external geom
Part::Geometry* g = this->ExternalGeo[-geoId-1];
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -38,6 +38,14 @@
namespace Sketcher
{

struct GeoEnum
{
static const int RtPnt = -1;
static const int HAxis = -1;
static const int VAxis = -2;
static const int RefExt = -3;
};

class SketcherExport SketchObject : public Part::Part2DObject
{
PROPERTY_HEADER(Sketcher::SketchObject);
Expand Down
18 changes: 9 additions & 9 deletions src/Mod/Sketcher/Gui/Command.cpp
Expand Up @@ -747,14 +747,14 @@ void CmdSketcherMirrorSketch::activated(int iMsg)

std::vector<Part::Geometry *> mirrorgeo (tempgeo.begin()+addedGeometries+1,tempgeo.end());
std::vector<Sketcher::Constraint *> mirrorconstr (tempconstr.begin()+addedConstraints+1,tempconstr.end());
for(std::vector<Sketcher::Constraint *>::const_iterator itc=mirrorconstr.begin(); itc != mirrorconstr.end(); ++itc) {

for (std::vector<Sketcher::Constraint *>::const_iterator itc=mirrorconstr.begin(); itc != mirrorconstr.end(); ++itc) {

if((*itc)->First!=Sketcher::Constraint::GeoUndef || (*itc)->First==-1 || (*itc)->First==-2) // not x, y axes or origin
if ((*itc)->First!=Sketcher::Constraint::GeoUndef || (*itc)->First==Sketcher::GeoEnum::HAxis || (*itc)->First==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
(*itc)->First-=(addedGeometries+1);
if((*itc)->Second!=Sketcher::Constraint::GeoUndef || (*itc)->Second==-1 || (*itc)->Second==-2) // not x, y axes or origin
if ((*itc)->Second!=Sketcher::Constraint::GeoUndef || (*itc)->Second==Sketcher::GeoEnum::HAxis || (*itc)->Second==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
(*itc)->Second-=(addedGeometries+1);
if((*itc)->Third!=Sketcher::Constraint::GeoUndef || (*itc)->Third==-1 || (*itc)->Third==-2) // not x, y axes or origin
if ((*itc)->Third!=Sketcher::Constraint::GeoUndef || (*itc)->Third==Sketcher::GeoEnum::HAxis || (*itc)->Third==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
(*itc)->Third-=(addedGeometries+1);
}

Expand Down Expand Up @@ -818,14 +818,14 @@ void CmdSketcherMergeSketches::activated(int iMsg)

int addedConstraints=mergesketch->addConstraints(Obj->Constraints.getValues());

for(int i=0; i<=(addedConstraints-baseConstraints); i++){
for (int i=0; i<=(addedConstraints-baseConstraints); i++){
Sketcher::Constraint * constraint= mergesketch->Constraints.getValues()[i+baseConstraints];

if(constraint->First!=Sketcher::Constraint::GeoUndef || constraint->First==-1 || constraint->First==-2) // not x, y axes or origin
if (constraint->First!=Sketcher::Constraint::GeoUndef || constraint->First==Sketcher::GeoEnum::HAxis || constraint->First==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
constraint->First+=baseGeometry;
if(constraint->Second!=Sketcher::Constraint::GeoUndef || constraint->Second==-1 || constraint->Second==-2) // not x, y axes or origin
if (constraint->Second!=Sketcher::Constraint::GeoUndef || constraint->Second==Sketcher::GeoEnum::HAxis || constraint->Second==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
constraint->Second+=baseGeometry;
if(constraint->Third!=Sketcher::Constraint::GeoUndef || constraint->Third==-1 || constraint->Third==-2) // not x, y axes or origin
if (constraint->Third!=Sketcher::Constraint::GeoUndef || constraint->Third==Sketcher::GeoEnum::HAxis || constraint->Third==Sketcher::GeoEnum::VAxis) // not x, y axes or origin
constraint->Third+=baseGeometry;
}

Expand Down

0 comments on commit 222e9b6

Please sign in to comment.