static PyObject * loftOnCurve(PyObject *self, PyObject *args) { Part::TopoShapePy *pcObject; PyObject *pcTopoObj,*pcListObj; float x=0.0f,y=0.0f,z=1.0f,size = 0.1f; if (!PyArg_ParseTuple(args, "O!O(fff)f", &(Part::TopoShapePy::Type), &pcTopoObj,&pcListObj,&x,&y,&z,&size)) // convert args: Python->C // if (!PyArg_ParseTuple(args, "O!O!", &(App::TopoShapePy::Type), &pcTopoObj,&PyList_Type,&pcListObj,x,y,z,size)) // convert args: Python->C return NULL; // NULL triggers exception pcObject = (Part::TopoShapePy*)pcTopoObj; MeshCore::MeshKernel M; std::vector<Base::Vector3f> poly; if (!PyList_Check(pcListObj)) Py_Error(Base::BaseExceptionFreeCADError,"List of Tuble of three or two floats needed as second parameter!"); int nSize = PyList_Size(pcListObj); for (int i=0; i<nSize;++i) { PyObject* item = PyList_GetItem(pcListObj, i); if (!PyTuple_Check(item)) Py_Error(Base::BaseExceptionFreeCADError,"List of Tuble of three or two floats needed as second parameter!"); int nTSize = PyTuple_Size(item); if(nTSize != 2 && nTSize != 3) Py_Error(Base::BaseExceptionFreeCADError,"List of Tuble of three or two floats needed as second parameter!"); Base::Vector3f vec(0,0,0); for(int l = 0; l < nTSize;l++) { PyObject* item2 = PyTuple_GetItem(item, l); if (!PyFloat_Check(item2)) Py_Error(Base::BaseExceptionFreeCADError,"List of Tuble of three or two floats needed as second parameter!"); vec[l] = (float)PyFloat_AS_DOUBLE(item2); } poly.push_back(vec); } PY_TRY { TopoDS_Shape aShape = pcObject->getTopoShapePtr()->_Shape; // use the MeshAlgos MeshPart::MeshAlgos::LoftOnCurve(M,aShape,poly,Base::Vector3f(x,y,z),size); } PY_CATCH; return new Mesh::MeshPy(new Mesh::MeshObject(M)); }
long resample(long skts_ordinal, int freq1, int freq2, char relation) { freq_conv_func func = get_asfreq_func(freq1, freq2, 0); asfreq_info finfo; get_asfreq_info(freq1, freq2, &finfo); long val = (*func)(skts_ordinal, relation, &finfo); if (val == INT_ERR_CODE) Py_Error(PyExc_ValueError, "Unable to convert to desired frequency."); return val; onError: return INT_ERR_CODE; }
long_t asfreq(long_t period_ordinal, int freq1, int freq2, char relation) { freq_conv_func func = get_asfreq_func(freq1, freq2, 0); asfreq_info finfo; get_asfreq_info(freq1, freq2, &finfo); long_t val = (*func)(period_ordinal, relation, &finfo); if (val == INT_ERR_CODE) { Py_Error(PyExc_ValueError, "Unable to convert to desired frequency."); goto onError; } return val; onError: return INT_ERR_CODE; }
/* Return the year offset, that is the absolute date of the day 31.12.(year-1) in the given calendar. Note: For the Julian calendar we shift the absdate (which is measured using the Gregorian Epoch) value by two days because the Epoch (0001-01-01) in the Julian calendar lies 2 days before the Epoch in the Gregorian calendar. */ static int dInfoCalc_YearOffset(npy_int64 year, int calendar) { year--; if (calendar == GREGORIAN_CALENDAR) { if (year >= 0 || -1/4 == -1) return year*365 + year/4 - year/100 + year/400; else return year*365 + (year-3)/4 - (year-99)/100 + (year-399)/400; } else if (calendar == JULIAN_CALENDAR) { if (year >= 0 || -1/4 == -1) return year*365 + year/4 - 2; else return year*365 + (year-3)/4 - 2; } Py_Error(PyExc_ValueError, "unknown calendar"); onError: return INT_ERR_CODE; }
/* Sets the date part of the date_info struct using the indicated calendar. XXX This could also be done using some integer arithmetics rather than with this iterative approach... */ static int dInfoCalc_SetFromAbsDate(register struct date_info *dinfo, npy_int64 absdate, int calendar) { register npy_int64 year; npy_int64 yearoffset; int leap,dayoffset; int *monthoffset; /* Approximate year */ if (calendar == GREGORIAN_CALENDAR) { year = (npy_int64)(((double)absdate) / 365.2425); } else if (calendar == JULIAN_CALENDAR) { year = (npy_int64)(((double)absdate) / 365.25); } else { Py_Error(PyExc_ValueError, "unknown calendar"); } if (absdate > 0) year++; /* Apply corrections to reach the correct year */ while (1) { /* Calculate the year offset */ yearoffset = dInfoCalc_YearOffset(year, calendar); if (PyErr_Occurred()) goto onError; /* Backward correction: absdate must be greater than the yearoffset */ if (yearoffset >= absdate) { year--; continue; } dayoffset = absdate - yearoffset; leap = dInfoCalc_Leapyear(year,calendar); /* Forward correction: non leap years only have 365 days */ if (dayoffset > 365 && !leap) { year++; continue; } break; } dinfo->year = year; dinfo->calendar = calendar; /* Now iterate to find the month */ monthoffset = month_offset[leap]; { register int month; for (month = 1; month < 13; month++) { if (monthoffset[month] >= dayoffset) break; } dinfo->month = month; dinfo->quarter = monthToQuarter(month); dinfo->day = dayoffset - month_offset[leap][month-1]; } dinfo->day_of_week = dInfoCalc_DayOfWeek(absdate); dinfo->day_of_year = dayoffset; dinfo->absdate = absdate; return 0; onError: return INT_ERR_CODE; }
/* generate an ordinal in period space */ npy_int64 get_period_ordinal(int year, int month, int day, int hour, int minute, int second, int microseconds, int picoseconds, int freq) { npy_int64 absdays, delta, seconds; npy_int64 weeks, days; npy_int64 ordinal, day_adj; int freq_group, fmonth, mdiff; freq_group = get_freq_group(freq); if (freq == FR_SEC || freq == FR_MS || freq == FR_US || freq == FR_NS) { absdays = absdate_from_ymd(year, month, day); delta = (absdays - ORD_OFFSET); seconds = (npy_int64)(delta * 86400 + hour * 3600 + minute * 60 + second); switch(freq) { case FR_MS: return seconds * 1000 + microseconds / 1000; case FR_US: return seconds * 1000000 + microseconds; case FR_NS: return seconds * 1000000000 + microseconds * 1000 + picoseconds / 1000; } return seconds; } if (freq == FR_MIN) { absdays = absdate_from_ymd(year, month, day); delta = (absdays - ORD_OFFSET); return (npy_int64)(delta*1440 + hour*60 + minute); } if (freq == FR_HR) { if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } delta = (absdays - ORD_OFFSET); return (npy_int64)(delta*24 + hour); } if (freq == FR_DAY) { return (npy_int64) (absdate_from_ymd(year, month, day) - ORD_OFFSET); } if (freq == FR_UND) { return (npy_int64) (absdate_from_ymd(year, month, day) - ORD_OFFSET); } if (freq == FR_BUS) { if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } weeks = days / 7; return (npy_int64)(days - weeks * 2) - BDAY_OFFSET; } if (freq_group == FR_WK) { if((ordinal = (npy_int64)absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } day_adj = freq - FR_WK; return (ordinal - (1 + day_adj)) / 7 + 1 - WEEK_OFFSET; } if (freq == FR_MTH) { return (year - BASE_YEAR) * 12 + month - 1; } if (freq_group == FR_QTR) { fmonth = freq - FR_QTR; if (fmonth == 0) fmonth = 12; mdiff = month - fmonth; if (mdiff < 0) mdiff += 12; if (month >= fmonth) mdiff += 12; return (year - BASE_YEAR) * 4 + (mdiff - 1) / 3; } if (freq_group == FR_ANN) { fmonth = freq - FR_ANN; if (fmonth == 0) fmonth = 12; if (month <= fmonth) { return year - BASE_YEAR; } else { return year - BASE_YEAR + 1; } } Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal"); onError: return INT_ERR_CODE; }
/* generate an ordinal in period space */ long_t get_period_ordinal(int year, int month, int day, int hour, int minute, int second, int freq) { int freq_group = get_freq_group(freq); int quarter=((month-1)/3)+1; if (freq == FR_SEC) { long_t absdays, delta; absdays = absdate_from_ymd(year, month, day); delta = (absdays - HIGHFREQ_ORIG); return (long_t)(delta*86400 + hour*3600 + minute*60 + second + 1); } if (freq == FR_MIN) { long_t absdays, delta; absdays = absdate_from_ymd(year, month, day); delta = (absdays - HIGHFREQ_ORIG); return (long_t)(delta*1440 + hour*60 + minute + 1); } if (freq == FR_HR) { long_t absdays, delta; if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } delta = (absdays - HIGHFREQ_ORIG); return (long_t)(delta*24 + hour + 1); } if (freq == FR_DAY) { return (long_t)absdate_from_ymd(year, month, day); } if (freq == FR_UND) { return (long_t)absdate_from_ymd(year, month, day); } if (freq == FR_BUS) { long_t weeks, days; if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } weeks = days/7; return (long_t)(days - weeks*2); } if (freq_group == FR_WK) { long_t adj_ordinal, ordinal, day_adj; if((ordinal = (long_t)absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } day_adj = (7 - (freq - FR_WK)) % 7; adj_ordinal = ordinal + ((7 - day_adj) - ordinal % 7) % 7; return adj_ordinal/7; } if (freq == FR_MTH) { return (year-1)*12 + month; } if (freq_group == FR_QTR) { return (year-1)*4 + quarter; } if (freq_group == FR_ANN) { return year; } Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal"); onError: return INT_ERR_CODE; }
/* generate an ordinal in period space */ int64_t get_period_ordinal(int year, int month, int day, int hour, int minute, int second, int freq) { int64_t absdays, delta; int64_t weeks, days; int64_t adj_ordinal, ordinal, day_adj; int freq_group, fmonth, mdiff, quarter; freq_group = get_freq_group(freq); if (freq == FR_SEC) { absdays = absdate_from_ymd(year, month, day); delta = (absdays - HIGHFREQ_ORIG); return (int64_t)(delta*86400 + hour*3600 + minute*60 + second + 1); } if (freq == FR_MIN) { absdays = absdate_from_ymd(year, month, day); delta = (absdays - HIGHFREQ_ORIG); return (int64_t)(delta*1440 + hour*60 + minute + 1); } if (freq == FR_HR) { if ((absdays = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } delta = (absdays - HIGHFREQ_ORIG); return (int64_t)(delta*24 + hour + 1); } if (freq == FR_DAY) { return (int64_t)absdate_from_ymd(year, month, day); } if (freq == FR_UND) { return (int64_t)absdate_from_ymd(year, month, day); } if (freq == FR_BUS) { if((days = absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } weeks = days/7; return (int64_t)(days - weeks*2); } if (freq_group == FR_WK) { if((ordinal = (int64_t)absdate_from_ymd(year, month, day)) == INT_ERR_CODE) { goto onError; } day_adj = (7 - (freq - FR_WK)) % 7; adj_ordinal = ordinal + ((7 - day_adj) - ordinal % 7) % 7; return adj_ordinal/7; } if (freq == FR_MTH) { return (year-1)*12 + month; } if (freq_group == FR_QTR) { fmonth = freq - FR_QTR; if (fmonth == 0) fmonth = 12; mdiff = month - fmonth; if (mdiff < 0) mdiff += 12; if (month >= fmonth) mdiff += 12; return 1 + (year - 1) * 4 + (mdiff - 1) / 3; } if (freq_group == FR_ANN) { fmonth = freq - FR_ANN; if (fmonth == 0) fmonth = 12; if (month <= fmonth) { return year; } else { return year + 1; } } Py_Error(PyExc_RuntimeError, "Unable to generate frequency ordinal"); onError: return INT_ERR_CODE; }