void RGraphicsSceneQt::exportRay(const RRay& ray) { bool created = beginPath(); Q_ASSERT(currentPainterPath.isValid()); // find largest view box over all attached views: RBox box; QList<RGraphicsView*>::iterator it; for (it=views.begin(); it!=views.end(); it++) { RBox b = (*it)->getBox(); box.growToIncludeBox(b); } // trim line to view box: RLine clippedLine = ray.getClippedLine(box); double offs = clippedLine.getStartPoint().getDistanceTo(ray.getBasePoint()); if (RMath::isSameDirection(ray.getBasePoint().getAngleTo(clippedLine.getStartPoint()), ray.getDirection1())) { offs *= -1; } exportLine(clippedLine, offs); currentPainterPath.setAlwaysRegen(true); if (created) { endPath(); } }
/** * Exports the given shapes as part of the geometry of the current entity. */ void RExporter::exportShape(QSharedPointer<RShape> shape) { if (shape.isNull()) { return; } QSharedPointer<RLine> line = shape.dynamicCast<RLine>(); if (!line.isNull()) { exportLine(*line.data()); } QSharedPointer<RArc> arc = shape.dynamicCast<RArc>(); if (!arc.isNull()) { exportArc(*arc.data()); } QSharedPointer<RCircle> circle = shape.dynamicCast<RCircle>(); if (!circle.isNull()) { exportCircle(*circle.data()); } QSharedPointer<RTriangle> triangle = shape.dynamicCast<RTriangle>(); if (!triangle.isNull()) { exportTriangle(*triangle.data()); } }
void RExporter::exportExplodable(const RExplodable& explodable, double offset) { QList<QSharedPointer<RShape> > sub = explodable.getExploded(); RLinetypePattern p = getLinetypePattern(); if (!p.isValid() || p.getNumDashes() <= 1 || draftMode || screenBasedLinetypes || twoColorSelectedMode) { for (int i=0; i<sub.length(); i++) { QSharedPointer<RLine> lineP = sub[i].dynamicCast<RLine>(); if (!lineP.isNull()) { exportLine(*lineP.data()); continue; } QSharedPointer<RArc> arc = sub[i].dynamicCast<RArc>(); if (!arc.isNull()) { exportArc(*arc.data()); continue; } } return; } if (getEntity()!=NULL && (getEntity()->getType()!=RS::EntitySpline || RSpline::hasProxy())) { // all explodable entities including splines if we have a spline proxy: RShapesExporter(*this, sub, offset); return; } // use alternative algorithm for splines if we don't have a spline proxy: double dist; for (int i=0; i<sub.length(); i++) { QSharedPointer<RLine> lineP = sub[i].dynamicCast<RLine>(); if (!lineP.isNull()) { RLine line = *lineP.data(); dist = exportLine(line, offset); offset -= lineP->getLength(); continue; } QSharedPointer<RArc> arc = sub[i].dynamicCast<RArc>(); if (!arc.isNull()) { exportArc(*arc.data(), offset); offset -= arc->getLength(); continue; } } }
bool CGpio::InitU401Pins() { char buf[256]; int gpioNumber, direction; FILE *cmd = NULL; #ifndef WIN32 cmd = fopen("/opt/u401_cfg.txt", "r"); #else cmd = fopen("E:\\u401_cfg.txt", "r"); #endif if (cmd == NULL) { _log.Log(LOG_ERROR, "%s: Failed to open /opt/u401_cfg.txt", __func__); return false; } while (fgets(buf, sizeof(buf), cmd) != 0) { // Decode U401 GPIOs as below: // // GPIO,DIR // 0,out, // 7,in, std::string exportLine(buf); //std::cout << "Processing line: " << exportLine; std::vector<std::string> sresults; StringSplit(exportLine, ",", sresults); if (sresults.empty()) continue; if (sresults[0] == "GPIO") continue; if (sresults.size() == 3) { gpioNumber = atoi(sresults[0].c_str()); if ((gpioNumber >= 0) && (gpioNumber < MAX_GPIO_U401)) { if (sresults[1] == "out") pins.push_back(CGpioPin(gpioNumber + CGPIO_STARTID_U401, CGPIOPIN_U401, "gpio" + sresults[0], CGPIO_DIR_OUT, true)); else pins.push_back(CGpioPin(gpioNumber + CGPIO_STARTID_U401, CGPIOPIN_U401, "gpio" + sresults[0], CGPIO_DIR_IN, true)); } else { _log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", buf); } } } fclose(cmd); if (pins.size() > 0) { std::sort(pins.begin(), pins.end()); // debug //for(std::vector<CGpioPin>::iterator it = pins.begin(); it != pins.end(); ++it) { // CGpioPin pin=*it; // std::cout << "Pin " << pin.GetId() << " : " << pin.GetLabel() << ", " << pin.GetDirection() << ", " << pin.GetIsExported() << std::endl; //} } else { _log.Log(LOG_ERROR, "%s: Failed to detect any pins", __func__); return false; } return true; }
ccTracePolylineTool::ccTracePolylineTool(ccPickingHub* pickingHub, QWidget* parent) : ccOverlayDialog(parent) , Ui::TracePolyLineDlg() , m_polyTip(0) , m_polyTipVertices(0) , m_poly3D(0) , m_poly3DVertices(0) , m_done(false) , m_pickingHub(pickingHub) { assert(pickingHub); setupUi(this); setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); connect(saveToolButton, SIGNAL(clicked()), this, SLOT(exportLine())); connect(resetToolButton, SIGNAL(clicked()), this, SLOT(resetLine())); connect(continueToolButton, SIGNAL(clicked()), this, SLOT(continueEdition())); connect(validButton, SIGNAL(clicked()), this, SLOT(apply())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); connect(widthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onWidthSizeChanged(int))); //add shortcuts addOverridenShortcut(Qt::Key_Escape); //escape key for the "cancel" button addOverridenShortcut(Qt::Key_Return); //return key for the "apply" button connect(this, SIGNAL(shortcutTriggered(int)), this, SLOT(onShortcutTriggered(int))); m_polyTipVertices = new ccPointCloud("Tip vertices"); m_polyTipVertices->reserve(2); m_polyTipVertices->addPoint(CCVector3(0, 0, 0)); m_polyTipVertices->addPoint(CCVector3(1, 1, 1)); m_polyTipVertices->setEnabled(false); m_polyTip = new ccPolyline(m_polyTipVertices); m_polyTip->setForeground(true); m_polyTip->setTempColor(ccColor::green); m_polyTip->set2DMode(true); m_polyTip->reserve(2); m_polyTip->addPointIndex(0, 2); m_polyTip->setWidth(widthSpinBox->value() < 2 ? 0 : widthSpinBox->value()); //'1' is equivalent to the default line size m_polyTip->addChild(m_polyTipVertices); validButton->setEnabled(false); }
void RExporter::exportExplodable(const RExplodable& explodable, double offset) { QList<QSharedPointer<RShape> > sub = explodable.getExploded(); QList<QSharedPointer<RShape> >::iterator it; for (it=sub.begin(); it!=sub.end(); ++it) { QSharedPointer<RLine> line = (*it).dynamicCast<RLine>(); if (!line.isNull()) { exportLine(*line.data(), offset); offset -= line->getLength(); continue; } QSharedPointer<RArc> arc = (*it).dynamicCast<RArc>(); if (!arc.isNull()) { exportArc(*arc.data(), offset); offset -= arc->getLength(); continue; } } }
void RGraphicsSceneQt::exportThickLine(const RLine& line, double w1, double w2) { if (RPolyline::hasProxy()) { bool hasCurrentPath = false; if (currentPainterPath.isValid()) { hasCurrentPath = true; endPath(); } beginPath(); RPolyline::getPolylineProxy()->exportThickLine(currentPainterPath, line, w1, w2); currentPainterPath.setBrush(currentPen.color()); currentPainterPath.setPen(QPen(Qt::NoPen)); endPath(); if (hasCurrentPath) { beginPath(); } } else { exportLine(line); } }
/* * static * One-shot method to initialize pins * */ bool CGpio::InitPins() { char buf[256]; bool exports[MAX_GPIO+1] = { false }; int gpioNumber; FILE *cmd = NULL; // 1. List exports and parse the result #ifndef WIN32 cmd = popen("gpio exports", "r"); #else cmd = fopen("E:\\exports.txt", "r"); #endif while (fgets(buf, sizeof(buf), cmd) != 0) { // Decode GPIO pin number from the output formatted as follows: // // GPIO Pins exported: // 17: out 0 none // 18: in 1 none // // 00000000001111111111 // 01234567890123456789 std::string exportLine(buf); //std::cout << "Processing line: " << exportLine; std::vector<std::string> sresults; StringSplit(exportLine, " :", sresults); if (sresults.empty()) continue; if (sresults[0] == "GPIO") continue; if (sresults.size() >= 4) { gpioNumber = atoi(sresults[0].c_str()); if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) { exports[gpioNumber] = true; } else { _log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", buf); } } } #ifndef WIN32 pclose(cmd); #else fclose(cmd); #endif // 2. List the full pin set and parse the result #ifndef WIN32 cmd = popen("gpio readall", "r"); #else cmd = fopen("E:\\readall.txt", "r"); #endif while (fgets(buf, sizeof(buf), cmd) != 0) { // Decode IN and OUT lines from the output formatted as follows: // // Old style (wiringPi<=2.16): // +----------+-Rev1-+------+--------+------+-------+ // | wiringPi | GPIO | Phys | Name | Mode | Value | // +----------+------+------+--------+------+-------+ // | 0 | 17 | 11 | GPIO 0 | IN | Low | // | 1 | 18 | 12 | GPIO 1 | IN | Low | // | 2 | 21 | 13 | GPIO 2 | IN | Low | // | 3 | 22 | 15 | GPIO 3 | IN | Low | // ... // // New style: // +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+ // | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | // +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ // | | | 3.3v | | | 1 || 2 | | | 5v | | | // | 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5V | | | // | 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | | // | 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 | // ... // // 0000000000111111111122222222223333333333444444444455555555556666666666777777777 // 0123456789012345678901234567890123456789012345678901234567890123456789012345678 std::string line(buf); std::vector<std::string> fields; //std::cout << "Processing line: " << line; StringSplit(line, "|", fields); if (fields.size()<7) continue; //std::cout << "# fields: " << fields.size() << std::endl; // trim each field for (size_t i = 0; i < fields.size(); i++) { fields[i]=stdstring_trim(fields[i]); //std::cout << "fields[" << i << "] = '" << fields[i] << "'" << std::endl; } if (fields.size() == 7) { // Old style if (fields[0] != "wiringPi") { gpioNumber = atoi(fields[1].c_str()); if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) { pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[1] + " (" + fields[3] + ") on pin " + fields[2], fields[4] == "IN", fields[4] == "OUT", exports[gpioNumber])); } else { _log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[1].c_str()); } } } else if (fields.size() == 14) { // New style if (fields[1].length() > 0) { gpioNumber = atoi(fields[1].c_str()); if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) { pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[1] + " (" + fields[3] + ") on pin " + fields[6], (fields[4] == "IN"), (fields[4] == "OUT"), exports[gpioNumber])); } else { _log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[1].c_str()); } } if (fields[12].length() > 0) { gpioNumber = atoi(fields[12].c_str()); if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) { pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[12] + " (" + fields[10] + ") on pin " + fields[7], fields[9] == "IN", fields[9] == "OUT", exports[gpioNumber])); } else { _log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[12].c_str()); } } } } #ifndef WIN32 pclose(cmd); #else fclose(cmd); #endif if (pins.size() > 0) { std::sort(pins.begin(), pins.end()); // debug //for(std::vector<CGpioPin>::iterator it = pins.begin(); it != pins.end(); ++it) { // CGpioPin pin=*it; // std::cout << "Pin " << pin.GetId() << " : " << pin.GetLabel() << ", " << pin.GetIsInput() << ", " << pin.GetIsOutput() << ", " << pin.GetIsExported() << std::endl; //} } else { _log.Log(LOG_ERROR, "GPIO: Failed to detect any pins, make sure you exported them!"); return false; } return true; }
void ccTracePolylineTool::apply() { exportLine(); stop(true); }