//! \brief Moves port2 to \a newLocalPos and adjust's the wire's lines. void Wire::movePort2(const QPointF& newLocalPos) { port2()->setPos(newLocalPos); if(m_wLines.isEmpty()) { return initWireline(); } QPointF referencePos = port2()->pos(); if(m_wLines.size() == 1) { m_wLines.prepend(WireLine(port1()->pos(), port1()->pos())); } WireLine &last = m_wLines.last(); WireLine &last_but_one = m_wLines[m_wLines.size() - 2]; Q_ASSERT(!last.isOblique()); Q_ASSERT(!last_but_one.isOblique()); { bool should_set_x = ((last.isNull() && (last_but_one.isNull() || last_but_one.isHorizontal())) || (!last.isNull() && last.isVertical())); if(should_set_x) { last.setX(referencePos.x()); } else { last.setY(referencePos.y()); } last.setP2(referencePos); } referencePos = last.p1(); { bool should_set_y = ((last_but_one.isNull() && (last.isNull() || last.isVertical())) || (!last_but_one.isNull() && last_but_one.isHorizontal())); if(should_set_y) { last_but_one.setY(referencePos.y()); } else { last_but_one.setX(referencePos.x()); } last_but_one.setP2(referencePos); } updateGeometry(); }
//! \brief Moves port1 to \a newLocalPos and adjust's the wire's lines. void Wire::movePort1(const QPointF& newLocalPos) { port1()->setPos(newLocalPos); // This is true when wire is created if(m_wLines.isEmpty()) { return initWireline(); } QPointF referencePos = port1()->pos(); if(m_wLines.size() == 1) { m_wLines.append(WireLine(port2()->pos(), port2()->pos())); } WireLine &first = m_wLines[0]; WireLine &second = m_wLines[1]; Q_ASSERT(!first.isOblique()); Q_ASSERT(!second.isOblique()); { bool should_set_x = ((first.isNull() && (second.isNull() || second.isHorizontal())) || (!first.isNull() && first.isVertical())); if(should_set_x) { first.setX(referencePos.x()); } else { first.setY(referencePos.y()); } first.setP1(referencePos); } referencePos = first.p2(); { bool should_set_y = ((second.isNull() && (first.isNull() || first.isVertical())) || (!second.isNull() && second.isHorizontal())); if(should_set_y) { second.setY(referencePos.y()); } else { second.setX(referencePos.x()); } second.setP1(referencePos); } updateGeometry(); }
/*! * \brief Initialize wire line used on wire creation * \note assert m_wLines.isEmpty() * \todo BR->GPK document inter */ void Wire::initWireline() { Q_ASSERT(m_wLines.isEmpty()); QPointF inter = QPointF(port1()->pos().x(), port2()->pos().y()); /* create two wire line */ m_wLines << WireLine(port1()->pos(), inter); m_wLines << WireLine(inter, port2()->pos()); /* update wire */ updateGeometry(); }
/*! * \brief Constructs a wire between \a startPort and \a endPort. * * Also connects the wire's port's to coinciding ports. * \bug br->gpk: does the new port is a purpose?? */ Wire::Wire(Port *startPort, Port *endPort, SchematicScene *scene) : QucsItem(0, scene), m_grabbedIndex(-1) { QPointF startPos = startPort->scenePos(); QPointF endPos = endPort->scenePos(); /* set position */ setPos((startPos + endPos)/2); /* set flags */ setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable); #if QT_VERSION >= 0x040600 setFlag(ItemSendsGeometryChanges, true); setFlag(ItemSendsScenePositionChanges, true); #endif /* create port BR->GPK: Why not add startport and endport */ QPointF localStartPos = mapFromScene(startPos); QPointF localEndPos = mapFromScene(endPos); m_ports << new Port(this, localStartPos); m_ports << new Port(this, localEndPos); initWireline(); if(scene) { removeNullLines(); } port1()->connectTo(startPort); port2()->connectTo(endPort); }
//! \brief Moves port matching connection \a connections to scene pos \a scenePos. void Wire::movePort(QList<Port*> *connections, const QPointF& scenePos) { if(port1()->connections() == connections) { movePort1(mapFromScene(scenePos)); } else if(port2()->connections() == connections) { movePort2(mapFromScene(scenePos)); } else { qWarning() << "Wire::movePort() : Port not found"; } }
void portTest::testMoveConstructor() { //construct port1 with a given id and put it into InitializedState long id1 = newPortId++; PortMock port1(// true, // isOutput, id1); port1.failOnWrongState = true; port1.initialize(nullptr, nullptr, nullptr); CPPUNIT_ASSERT(port1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id1, port1.getId()); //construct port1_1 (like port1) long id2 = newPortId++; PortMock port2(// false, // isInput, id2); port2.failOnWrongState = true; port2.initialize(nullptr, nullptr, nullptr); CPPUNIT_ASSERT(port2.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id2, port2.getId()); // move port1 into port 1_1 PortMock port1_1 = std::move(port1); // move port2 into port 2_1 PortMock port2_1 = std::move(port2); // verify that port1_1 has got the characteristics of port1 CPPUNIT_ASSERT(port1_1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id1, port1_1.getId()); // verify that port2_1 has got the characteristics of port2 CPPUNIT_ASSERT(port2_1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id2, port2_1.getId()); // very that the remains of port1 characterize a dead port CPPUNIT_ASSERT_EQUAL(PortInvalidId, port1.getId()); CPPUNIT_ASSERT(port1.isDeletableState()); // very that the remains of port2 characterize a dead port CPPUNIT_ASSERT_EQUAL(PortInvalidId, port2.getId()); CPPUNIT_ASSERT(port2.isDeletableState()); //end port1_1.shutdown(nullptr, nullptr, false); port2_1.shutdown(nullptr, nullptr, false); }
/*! * \brief Moves wire by (\a dx, \a dy). * \sa beginGrabMode */ void Wire::grabMoveBy(qreal dx, qreal dy) { // assure atleast two wirelines presence at both ends. Q_ASSERT(m_grabbedIndex >= 2 && (m_wLines.size()-1-m_grabbedIndex) >= 2); /* now calculate the constant positions in the beginning and end. This position wont change when wire is moved. */ QPointF refPos1 = m_grabbedIndex == 2 ? port1()->pos() : m_wLines[m_grabbedIndex-3].p2(); QPointF refPos2 = m_wLines.size()-1-m_grabbedIndex == 2 ? port2()->pos() : m_wLines[m_grabbedIndex+3].p1(); QPointF inter1, inter2; // Move the grabbed line first and asserts its nature. WireLine& grabbedLine = m_wLines[m_grabbedIndex]; grabbedLine.translate(QPointF(dx, dy)); Q_ASSERT(grabbedLine.isHorizontal() || grabbedLine.isVertical()); // Calculate the intermediate points of the wirelines. if(grabbedLine.isHorizontal()) { inter1 = QPointF(grabbedLine.p1().x(), refPos1.y()); inter2 = QPointF(grabbedLine.p2().x(), refPos2.y()); } else { inter1 = QPointF(refPos1.x(), grabbedLine.p1().y()); inter2 = QPointF(refPos2.x(), grabbedLine.p2().y()); } // Modify wirelines to accomodate the changes. m_wLines[m_grabbedIndex-1] = WireLine(inter1, grabbedLine.p1()); m_wLines[m_grabbedIndex-2] = WireLine(refPos1, inter1); m_wLines[m_grabbedIndex+1] = WireLine(grabbedLine.p2(), inter2); m_wLines[m_grabbedIndex+2] = WireLine(inter2, refPos2); // Now update the wires. updateGeometry(); }
void Wire::saveData(Qucs::XmlWriter *writer) const { writer->writeStartElement("wire"); QPointF p1 = port1()->scenePos(); QPointF p2 = port2()->scenePos(); QString start = QString("%1,%2").arg(p1.x()).arg(p1.y()); QString end = QString("%1,%2").arg(p2.x()).arg(p2.y()); QString pos_str = QString("%1,%2").arg(pos().x()).arg(pos().y()); writer->writeAttribute("start", start); writer->writeAttribute("end", end); writer->writeAttribute("pos", pos_str); //write the lines foreach(WireLine line, m_wLines) { writer->writeEmptyElement("line"); writer->writeAttribute("x1", QString::number(line.x1())); writer->writeAttribute("y1", QString::number(line.y1())); writer->writeAttribute("x2", QString::number(line.x2())); writer->writeAttribute("y2", QString::number(line.y2())); }
//! \brief Try to connect ports void Wire::tryConnectPorts() { tryConnectPort(port1()); tryConnectPort(port2()); }
JNIEXPORT jlong JNICALL Java_gurux_io_NativeCode_openSerialPort (JNIEnv* env, jclass clazz, jstring port, jlongArray closing) { jboolean isCopy; #if defined(_WIN32) || defined(_WIN64) const char* pPort = env->GetStringUTFChars(port, &isCopy); std::string port2(pPort); std::string buff("\\\\.\\"); buff.append(pPort); env->ReleaseStringUTFChars(port, pPort); //Open serial port for read / write. Port can't share. HANDLE hComPort = CreateFileA(buff.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (hComPort == INVALID_HANDLE_VALUE) { ReportError(env, GetLastError()); } DCB dcb = { 0}; dcb.DCBlength = sizeof(DCB); dcb.BaudRate = 9600; dcb.fBinary = 1; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fRtsControl = DTR_CONTROL_ENABLE; dcb.fOutX = dcb.fInX = 0; //CTS handshaking on output. dcb.fOutxCtsFlow = DTR_CONTROL_DISABLE; //DSR handshaking on output dcb.fOutxDsrFlow = DTR_CONTROL_DISABLE; //Abort all reads and writes on Error. dcb.fAbortOnError = 1; dcb.ByteSize = 8; //Parity = None. dcb.Parity = 0; //StopBits = 1; dcb.StopBits = 0; int ret; if ((ret = GXSetCommState(hComPort, &dcb)) != 0) { ReportError(env, ret); } jlong hClosing = (jlong) ::CreateEvent(NULL, TRUE, FALSE, NULL); env->SetLongArrayRegion(closing, 0, 1, &hClosing); return (long) hComPort; #else //#if defined(__LINUX__) const char* pPort = env->GetStringUTFChars (port, &isCopy); std::string buff (pPort); env->ReleaseStringUTFChars (port, pPort); // file description for the serial port int hComPort; // read/write | not controlling term | don't wait for DCD line signal. hComPort = open (buff.c_str (), O_RDWR | O_NOCTTY | O_NONBLOCK); if (hComPort == -1)// if open is unsuccessful. { buff.insert (0, "Failed to Open port: "); ReportError (env, buff.c_str ()); } else { if (!isatty (hComPort)) { ReportError (env, "Failed to Open port. This is not a serial port."); } if ((ioctl (hComPort, TIOCEXCL) == -1)) { ReportError (env, "Failed to Open port. Exclusive access denied."); } struct termios options; memset (&options, 0, sizeof(options)); options.c_iflag = 0; options.c_oflag = 0; options.c_cflag = CS8 | CREAD | CLOCAL; // 8n1, see termios.h for more information options.c_lflag = 0; options.c_cc[VMIN] = 1; options.c_cc[VTIME] = 5; //Set Baud Rates cfsetospeed (&options, B9600); cfsetispeed (&options, B9600); //hardware flow control is used as default. //options.c_cflag |= CRTSCTS; if (tcsetattr (hComPort, TCSAFLUSH, &options) != 0) { ReportError (env, "Failed to Open port. tcsetattr failed."); //errno } } return hComPort; #endif }
// // Fix a compile error - see http://stackoverflow.com/questions/920500/what-is-the-purpose-of-cxa-pure-virtual for details. // // extern "C" void __cxa_pure_virtual() { while (1); } // // The main entry point // int main(void) { // // Board and port initialisations // StellarisLaunchpad pad; StellarisPort port1(SYSCTL_PERIPH_GPIOD); StellarisPort port2(SYSCTL_PERIPH_GPIOE); // // Create a set of objects representing the output pins // StellarisPortPin clock(GPIO_PORTD_BASE, GPIO_PIN_1); StellarisPortPin shift(GPIO_PORTD_BASE, GPIO_PIN_2); StellarisPortPin chipSelect(GPIO_PORTD_BASE, GPIO_PIN_3); StellarisPortPin a(GPIO_PORTE_BASE, GPIO_PIN_1); StellarisPortPin b(GPIO_PORTE_BASE, GPIO_PIN_2); StellarisPortPin c(GPIO_PORTE_BASE, GPIO_PIN_3); // // Create and initialise the LedArrayDriver // LedArrayDriver led(&clock, &chipSelect, &shift, &a,&b,&c, NBR_OF_DISPLAY_ROWS, NBR_OF_DISPLAY_COLUMNS); led.init(); AsciiMessage welcome("**** Welcome to the Museum of Computing - open Fridays 10am to 4pm and Saturdays 9:30am to 5pm ****"); AsciiMessage exhib1("**** Visit our \"Gaming on the Go\" exhibition - 35 years of handheld games consoles ****"); AsciiMessage retroGaming("**** Join our computer games sessions on Saturdays for some retro gaming ****"); AsciiMessage website("**** See us on the web at http://www.museum-of-computing.org.uk/ ****"); AsciiMessage hackspace("**** Join the Swindon Hackspace at the Museum of Computing - Wednesdays 6:30pm to 10pm ****"); AsciiMessage compClub("**** Ask about our Kids Computer Club on Saturdays ****"); AsciiMessage schoolVisit("**** Arrange a school visit and take part in a tour of the museum, quizzes and mini projects ****"); AsciiMessage shop("**** Our shop has a range of gifts and souvenirs ****"); RepeatedGraphic multiInvader(invader, 10, 8); AnimatedGraphic pacman(animPacman, 17, 7);// columns * frames AnimatedGraphic invader(animInvader, 11, 4);// columns * frames LeftScroller scrollLeft1(led, invader, 2, displayBuffer); LeftScroller scrollLeft2(led, welcome, 1, displayBuffer); LeftScroller scrollLeft3(led, exhib1, 1, displayBuffer); LeftScroller scrollLeft4(led, multiInvader, 1, displayBuffer); LeftScroller scrollLeft5(led, retroGaming, 1, displayBuffer); LeftScroller scrollLeft6(led, pacman, 1, displayBuffer); LeftScroller scrollLeft7(led, compClub, 1, displayBuffer); LeftScroller scrollLeft8(led, schoolVisit, 1, displayBuffer); LeftScroller scrollLeft9(led, website, 1, displayBuffer); LeftScroller scrollLeft10(led, shop, 1, displayBuffer); LeftScroller scrollLeft11(led, hackspace, 1, displayBuffer); do { scrollLeft1.init(); while(scrollLeft1.animate()); scrollLeft2.init(); while(scrollLeft2.animate()); scrollLeft3.init(); while(scrollLeft3.animate()); scrollLeft4.init(); while(scrollLeft4.animate()); scrollLeft5.init(); while(scrollLeft5.animate()); scrollLeft6.init(); while(scrollLeft6.animate()); scrollLeft7.init(); while(scrollLeft7.animate()); scrollLeft8.init(); while(scrollLeft8.animate()); scrollLeft9.init(); while(scrollLeft9.animate()); scrollLeft10.init(); while(scrollLeft10.animate()); scrollLeft11.init(); while(scrollLeft11.animate()); } while(1); }