00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "PreCompiled.h"
00024 #include <strstream>
00025 #include "Mod/Sketcher/App/Constraint.h"
00026
00027
00028 #include "ConstraintPy.h"
00029 #include "ConstraintPy.cpp"
00030
00031 using namespace Sketcher;
00032
00033 PyObject *ConstraintPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00034 {
00035
00036 return new ConstraintPy(new Constraint);
00037 }
00038
00039
00040 int ConstraintPy::PyInit(PyObject* args, PyObject* )
00041 {
00042 if (PyArg_ParseTuple(args, "")) {
00043 return 0;
00044 }
00045
00046 PyErr_Clear();
00047
00048 char *ConstraintType;
00049 int FirstIndex = Constraint::GeoUndef;
00050 int FirstPos = none;
00051 int SecondIndex= Constraint::GeoUndef;
00052 int SecondPos = none;
00053 int ThirdIndex = Constraint::GeoUndef;
00054 int ThirdPos = none;
00055 double Value = 0;
00056
00057
00058 PyObject* index_or_value;
00059 int any_index;
00060
00061
00062 if (PyArg_ParseTuple(args, "si", &ConstraintType, &FirstIndex)) {
00063 if (strcmp("Horizontal",ConstraintType) == 0) {
00064 this->getConstraintPtr()->Type = Horizontal;
00065 this->getConstraintPtr()->First = FirstIndex;
00066 return 0;
00067 }
00068 else if (strcmp("Vertical",ConstraintType) == 0) {
00069 this->getConstraintPtr()->Type = Vertical;
00070 this->getConstraintPtr()->First = FirstIndex;
00071 return 0;
00072 }
00073 }
00074 PyErr_Clear();
00075
00076 if (PyArg_ParseTuple(args, "siO", &ConstraintType, &FirstIndex, &index_or_value)) {
00077
00078 if (PyInt_Check(index_or_value)) {
00079 SecondIndex = PyInt_AsLong(index_or_value);
00080 bool valid = false;
00081 if (strcmp("Tangent",ConstraintType) == 0) {
00082 this->getConstraintPtr()->Type = Tangent;
00083 valid = true;
00084 }
00085 else if (strcmp("Parallel",ConstraintType) == 0) {
00086 this->getConstraintPtr()->Type = Parallel;
00087 valid = true;
00088 }
00089 else if (strcmp("Perpendicular",ConstraintType) == 0) {
00090 this->getConstraintPtr()->Type = Perpendicular;
00091 valid = true;
00092 }
00093 else if (strcmp("Equal",ConstraintType) == 0) {
00094 this->getConstraintPtr()->Type = Equal;
00095 valid = true;
00096 }
00097 if (valid) {
00098 this->getConstraintPtr()->First = FirstIndex;
00099 this->getConstraintPtr()->Second = SecondIndex;
00100 return 0;
00101 }
00102 }
00103
00104 else if (PyFloat_Check(index_or_value)) {
00105 Value = PyFloat_AsDouble(index_or_value);
00106 bool valid = false;
00107 if (strcmp("Distance",ConstraintType) == 0 ) {
00108 this->getConstraintPtr()->Type = Distance;
00109 valid = true;
00110 }
00111 else if (strcmp("Angle",ConstraintType) == 0 ) {
00112 this->getConstraintPtr()->Type = Angle;
00113 valid = true;
00114 }
00115 else if (strcmp("DistanceX",ConstraintType) == 0) {
00116 this->getConstraintPtr()->Type = DistanceX;
00117 valid = true;
00118 }
00119 else if (strcmp("DistanceY",ConstraintType) == 0) {
00120 this->getConstraintPtr()->Type = DistanceY;
00121 valid = true;
00122 }
00123 else if (strcmp("Radius",ConstraintType) == 0) {
00124 this->getConstraintPtr()->Type = Radius;
00125 valid = true;
00126 }
00127 if (valid) {
00128 this->getConstraintPtr()->First = FirstIndex;
00129 this->getConstraintPtr()->Value = Value;
00130 return 0;
00131 }
00132 }
00133 }
00134 PyErr_Clear();
00135
00136 if (PyArg_ParseTuple(args, "siiO", &ConstraintType, &FirstIndex, &any_index, &index_or_value)) {
00137
00138 if (PyInt_Check(index_or_value)) {
00139 FirstPos = any_index;
00140 SecondIndex = PyInt_AsLong(index_or_value);
00141 if (strcmp("Tangent", ConstraintType) == 0) {
00142 this->getConstraintPtr()->Type = Tangent;
00143 this->getConstraintPtr()->First = FirstIndex;
00144 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00145 this->getConstraintPtr()->Second = SecondIndex;
00146 return 0;
00147 }
00148 if (strcmp("PointOnObject", ConstraintType) == 0) {
00149 this->getConstraintPtr()->Type = PointOnObject;
00150 this->getConstraintPtr()->First = FirstIndex;
00151 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00152 this->getConstraintPtr()->Second = SecondIndex;
00153 return 0;
00154 }
00155 }
00156
00157
00158 else if (PyFloat_Check(index_or_value)) {
00159 SecondIndex = any_index;
00160 Value = PyFloat_AsDouble(index_or_value);
00161
00162
00163
00164
00165
00166
00167
00168
00169 if (strcmp("Angle",ConstraintType) == 0) {
00170 this->getConstraintPtr()->Type = Angle;
00171 this->getConstraintPtr()->First = FirstIndex;
00172 this->getConstraintPtr()->Second = SecondIndex;
00173 this->getConstraintPtr()->Value = Value;
00174 return 0;
00175 }
00176 else if (strcmp("DistanceX",ConstraintType) == 0) {
00177 FirstPos = SecondIndex;
00178 SecondIndex = -1;
00179 this->getConstraintPtr()->Type = DistanceX;
00180 this->getConstraintPtr()->First = FirstIndex;
00181 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00182 this->getConstraintPtr()->Value = Value;
00183 return 0;
00184 }
00185 else if (strcmp("DistanceY",ConstraintType) == 0) {
00186 FirstPos = SecondIndex;
00187 SecondIndex = -1;
00188 this->getConstraintPtr()->Type = DistanceY;
00189 this->getConstraintPtr()->First = FirstIndex;
00190 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00191 this->getConstraintPtr()->Value = Value;
00192 return 0;
00193 }
00194 }
00195 }
00196 PyErr_Clear();
00197
00198 if (PyArg_ParseTuple(args, "siiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &index_or_value)) {
00199
00200 if (PyInt_Check(index_or_value)) {
00201 SecondPos = PyInt_AsLong(index_or_value);
00202 bool valid = false;
00203 if (strcmp("Coincident", ConstraintType) == 0) {
00204 this->getConstraintPtr()->Type = Coincident;
00205 valid = true;
00206 }
00207 else if (strcmp("Horizontal", ConstraintType) == 0) {
00208 this->getConstraintPtr()->Type = Horizontal;
00209 valid = true;
00210 }
00211 else if (strcmp("Vertical", ConstraintType) == 0) {
00212 this->getConstraintPtr()->Type = Vertical;
00213 valid = true;
00214 }
00215 else if (strcmp("Tangent", ConstraintType) == 0) {
00216 this->getConstraintPtr()->Type = Tangent;
00217 valid = true;
00218 }
00219 if (valid) {
00220 this->getConstraintPtr()->First = FirstIndex;
00221 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00222 this->getConstraintPtr()->Second = SecondIndex;
00223 this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
00224 return 0;
00225 }
00226 }
00227
00228 else if (PyFloat_Check(index_or_value)) {
00229 Value = PyFloat_AsDouble(index_or_value);
00230 if (strcmp("Distance",ConstraintType) == 0 ) {
00231 this->getConstraintPtr()->Type = Distance;
00232 this->getConstraintPtr()->First = FirstIndex;
00233 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00234 this->getConstraintPtr()->Second = SecondIndex;
00235 this->getConstraintPtr()->Value = Value;
00236 return 0;
00237 }
00238 }
00239 }
00240 PyErr_Clear();
00241
00242 if (PyArg_ParseTuple(args, "siiiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &index_or_value)) {
00243
00244 if (PyInt_Check(index_or_value)) {
00245 ThirdIndex = PyInt_AsLong(index_or_value);
00246 if (strcmp("Symmetric",ConstraintType) == 0 ) {
00247 this->getConstraintPtr()->Type = Symmetric;
00248 this->getConstraintPtr()->First = FirstIndex;
00249 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00250 this->getConstraintPtr()->Second = SecondIndex;
00251 this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
00252 this->getConstraintPtr()->Third = ThirdIndex;
00253 return 0;
00254 }
00255 }
00256
00257 else if (PyFloat_Check(index_or_value)) {
00258 Value = PyFloat_AsDouble(index_or_value);
00259 bool valid=false;
00260 if (strcmp("Distance",ConstraintType) == 0 ) {
00261 this->getConstraintPtr()->Type = Distance;
00262 valid = true;
00263 }
00264 else if (strcmp("DistanceX",ConstraintType) == 0) {
00265 this->getConstraintPtr()->Type = DistanceX;
00266 valid = true;
00267 }
00268 else if (strcmp("DistanceY",ConstraintType) == 0) {
00269 this->getConstraintPtr()->Type = DistanceY;
00270 valid = true;
00271 }
00272 else if (strcmp("Angle",ConstraintType) == 0 ) {
00273 this->getConstraintPtr()->Type = Angle;
00274 valid = true;
00275 }
00276 if (valid) {
00277 this->getConstraintPtr()->First = FirstIndex;
00278 this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
00279 this->getConstraintPtr()->Second = SecondIndex;
00280 this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
00281 this->getConstraintPtr()->Value = Value;
00282 return 0;
00283 }
00284 }
00285 }
00286
00287 PyErr_SetString(PyExc_TypeError, "Constraint constructor accepts:\n"
00288 "-- empty parameter list\n"
00289 "-- Constraint type and index\n");
00290 return -1;
00291 }
00292
00293
00294 std::string ConstraintPy::representation(void) const
00295 {
00296 std::stringstream result;
00297 result << "<Constraint " ;
00298 switch(this->getConstraintPtr()->Type) {
00299 case None : result << "'None'>";break;
00300 case DistanceX : result << "'DistanceX'>";break;
00301 case DistanceY : result << "'DistanceY'>";break;
00302 case Coincident : result << "'Coincident'>";break;
00303 case Horizontal : result << "'Horizontal' (" << getConstraintPtr()->First << ")>";break;
00304 case Vertical : result << "'Vertical' (" << getConstraintPtr()->First << ")>";break;
00305 case Parallel : result << "'Parallel'>";break;
00306 case Tangent : result << "'Tangent'>";break;
00307 case Distance : result << "'Distance'>";break;
00308 case Angle : result << "'Angle'>";break;
00309 default : result << "'?'>";break;
00310 }
00311 return result.str();
00312 }
00313
00314 Py::Int ConstraintPy::getFirst(void) const
00315 {
00316 return Py::Int(this->getConstraintPtr()->First);
00317 }
00318
00319 void ConstraintPy::setFirst(Py::Int arg)
00320 {
00321 this->getConstraintPtr()->First = arg;
00322 }
00323
00324 Py::Int ConstraintPy::getSecond(void) const
00325 {
00326 return Py::Int(this->getConstraintPtr()->Second);
00327 }
00328
00329 void ConstraintPy::setSecond(Py::Int arg)
00330 {
00331 this->getConstraintPtr()->Second = arg;
00332 }
00333
00334 PyObject *ConstraintPy::getCustomAttributes(const char* ) const
00335 {
00336 return 0;
00337 }
00338
00339 int ConstraintPy::setCustomAttributes(const char* , PyObject* )
00340 {
00341 return 0;
00342 }