Exemple #1
0
Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) :
    Q3MainWindow(parent,name,f),
    canvas(c)
{
    editor = new FigureEditor(canvas,this);
    QMenuBar* menu = menuBar();

    Q3PopupMenu* file = new Q3PopupMenu( menu );
    file->insertItem("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F);
    file->insertItem("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E);
    file->insertItem("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N);
    file->insertSeparator();
    file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
    file->insertSeparator();
    file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q);
    menu->insertItem("&File", file);

    Q3PopupMenu* edit = new Q3PopupMenu( menu );
    edit->insertItem("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C);
    edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H);
    edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P);
    edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I);
    edit->insertItem("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T);
    edit->insertItem("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L);
    edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R);
    edit->insertItem("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S);
    edit->insertItem("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M );
    edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A);
    menu->insertItem("&Edit", edit);

    Q3PopupMenu* view = new Q3PopupMenu( menu );
    view->insertItem("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus);
    view->insertSeparator();
    view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown);
    view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp);
    view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus);
    view->insertItem("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left);
    view->insertItem("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right);
    view->insertItem("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up);
    view->insertItem("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down);
    view->insertItem("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home);
    menu->insertItem("&View", view);

    menu->insertSeparator();

    Q3PopupMenu* help = new Q3PopupMenu( menu );
    help->insertItem("&About", this, SLOT(help()), Qt::Key_F1);
    help->setItemChecked(dbf_id, TRUE);
    menu->insertItem("&Help",help);

    statusBar();

    setCentralWidget(editor);

    printer = 0;

    init();
}
static ES_Event DuringStateRotating(ES_Event Event) {
    ES_Event ReturnEvent = Event; // assme no re-mapping or comsumption

    // process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events
    if ((Event.EventType == ES_ENTRY) ||
         (Event.EventType == ES_ENTRY_HISTORY)) {
        // implement any entry actions required for this state machine
        
        // after that start any lower level machines that run in this state
        //StartLowerLevelSM( Event );
        // repeat the StartxxxSM() functions for concurrent state machines
        // on the lower level
        rotateCounterClockwise();
        //LineLostCounter = 0;
        ES_Timer_InitTimer(DRIVE_TIMER, ROTATION_TIME);
    } else if (Event.EventType == ES_EXIT) {
        // on exit, give the lower levels a chance to clean up first
        //RunLowerLevelSM(Event);
        // repeat for any concurrently running state machines
        // now do any local exit functionality
      
    } else { // do the 'during' function for this state
        // return either Event, if you don't want to allow the lower level machine
        // to remap the current event, or ReturnEvent if you do want to allow it.
    }
    return(ReturnEvent);
}
Exemple #3
0
uint8_t Shutter::goTo(uint8_t initPos, uint8_t endPos)
{
  uint8_t status = 0;

  if (initPos == 3 && endPos == 0) {
    status = rotateClockwise(240);
  }
  else if (initPos == 0 && endPos == 1) {
    Serial.println("Rotating clockwise");
    status = rotateClockwise(223);
  }
  else if (initPos == 0 && endPos == 2) {
    status = rotateClockwise(199);
  }
  else if (initPos == 1 && endPos == 0) {
    Serial.println("Rotating counterclockwise");
    status = rotateCounterClockwise(223);
  }
  else if (initPos == 1 && endPos == 2) {
    status = rotateClockwise(99);
  }
  else if (initPos == 2 && endPos == 0) {
    status = rotateCounterClockwise(199);
  }
  else if (initPos == 2 && endPos == 1) {
    status = rotateCounterClockwise(99);
  }
  else if (initPos == endPos) {
    status = 1;
  }

  if (status == 1) {
    return endPos;
  }
  else if (status == 2) {
    String buffer = "2,";
    buffer += _number;
    buffer += "\n";
    Serial.print(buffer);
    return 4;
  }
}
Exemple #4
0
Maze::Maze() {
    
    BasicMaze basicMaze;

    if (P()->useMazeFile()) {
        // TODO: MACK - clean this up (the file existence check should be in the utility class)
        QString mazeFilePath = Directory::get()->getResMazeDirectory() + P()->mazeFile();
        try {
            basicMaze = MazeFileUtilities::load(mazeFilePath);
        }
        catch (...) {
            QString reason = (
                SimUtilities::isFile(mazeFilePath) ?
                "invalid format" : "file doesn't exist");
            qCritical()
                << "Unable to initialize maze from file \"" << mazeFilePath
                << "\": " << reason << ".";
            SimUtilities::quit();
        }
    }
    else {
        // TODO: MACK - refactor this logic elsewhere
        QDir mazeAlgosDir(Directory::get()->getSrcMazeAlgosDirectory());
        mazeAlgosDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
        mazeAlgosDir.setSorting(QDir::Name | QDir::QDir::IgnoreCase);
        QStringList algos = mazeAlgosDir.entryList();

        // Check to see if there is some directory with the given name
        QString selectedMazeAlgo(P()->mazeAlgorithm());
        if (!algos.contains(selectedMazeAlgo)) {
             qCritical()
                << "\"" << P()->mazeAlgorithm() << "\" is not a valid maze"
                << " algorithm.";
             SimUtilities::quit();
        }

        // Get all files in the directory, recursively
        QDir selectedMazeAlgoDir(mazeAlgosDir);
        selectedMazeAlgoDir.cd(selectedMazeAlgo);
        selectedMazeAlgoDir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
        QDirIterator iterator(selectedMazeAlgoDir, QDirIterator::Subdirectories);
        QStringList relativePaths;
        QStringList absolutePaths;
        while (iterator.hasNext()) {
            iterator.next();
            relativePaths << iterator.fileName();
            absolutePaths << iterator.filePath();
        }

        // Deduce whether or not it's a C++ or Python algo
        QStringList args;
        if (relativePaths.contains(QString("Main.cpp"))) {
            // TODO: MACK args
            SimUtilities::quit();
        }
        else if (relativePaths.contains(QString("Main.py"))) {
            args << selectedMazeAlgoDir.absolutePath() + QString("/Main.py");
            args << QString::number(P()->generatedMazeWidth());
            args << QString::number(P()->generatedMazeHeight());
            for (int i = 0; i < args.size(); i += 1) {
                qInfo() << args.at(i);
            }
        }
        else {
            qCritical()
                << "No \"Main.{py,cpp}\" found in \""
                << selectedMazeAlgoDir.absolutePath() << "\"";
            SimUtilities::quit();
        }

        QProcess process; // TODO: MACK - pass in parent here
        process.start("python", args);
        process.waitForFinished();
        QByteArray bytes = process.readAll();
        basicMaze = MazeFileUtilities::loadBytes(bytes);
    }

    // Check to see if it's a valid maze
    m_isValidMaze = MazeChecker::isValidMaze(basicMaze).first;
    if (!m_isValidMaze) {
        qWarning()
            << "The maze failed validation. The mouse algorithm will not"
            << " execute.";
    }

    // Optionally save the maze
    if (!P()->useMazeFile() && P()->saveGeneratedMaze()) {
        MazeFileType type = STRING_TO_MAZE_FILE_TYPE.value(P()->generatedMazeType());
        QString mazeFilePath = Directory::get()->getResMazeDirectory() +
            P()->generatedMazeFile() + MAZE_FILE_TYPE_TO_SUFFIX.value(type);
        // TODO: MACK
        bool success = false; // MazeFileUtilities::save(basicMaze, mazeFilePath, type);
        if (success) {
            qInfo() << "Maze saved to \"" << mazeFilePath << "\".";
        }
        else {
            qWarning() << "Unable to save maze to \"" << mazeFilePath << "\".";
        }
    }

    // Mirror and rotate the maze
    if (P()->mazeMirrored()) {
        basicMaze = mirrorAcrossVertical(basicMaze);
        qInfo() << "Mirroring the maze across the vertical.";
    }
    for (int i = 0; i < P()->mazeRotations(); i += 1) {
        basicMaze = rotateCounterClockwise(basicMaze);
        qInfo() << "Rotating the maze counter-clockwise (" << i + 1 << ").";
    }

    // Then, store whether or not the maze is an official maze
    m_isOfficialMaze = m_isValidMaze && MazeChecker::isOfficialMaze(basicMaze).first;
    if (m_isValidMaze && !m_isOfficialMaze) {
        qWarning() << "The maze did not pass the \"is official maze\" tests.";
    }

    // Load the maze given by the maze generation algorithm
    m_maze = initializeFromBasicMaze(basicMaze);
}
Exemple #5
0
Maze::Maze() {
    
    std::vector<std::vector<BasicTile>> basicMaze;

    if (P()->useMazeFile()) {
        std::string mazeFilePath = Directory::getResMazeDirectory() + P()->mazeFile();
        try {
            basicMaze = MazeFileUtilities::loadMaze(mazeFilePath);
        }
        catch (...) {
            std::string reason = (
                SimUtilities::isFile(mazeFilePath) ?
                "invalid format" : "file doesn't exist");
            L()->error(
                "Unable to initialize maze from file \"%v\": %v.",
                mazeFilePath,
                reason);
            SimUtilities::quit();
        }
    }
    else {
        if (!MazeAlgorithms::isMazeAlgorithm(P()->mazeAlgorithm())) {
            L()->error("\"%v\" is not a valid maze algorithm.", P()->mazeAlgorithm());
            SimUtilities::quit();
        }
        basicMaze = getBlankBasicMaze(P()->generatedMazeWidth(), P()->generatedMazeHeight());
        MazeInterface mazeInterface(&basicMaze);
        MazeAlgorithms::getMazeAlgorithm(P()->mazeAlgorithm())->generate(
            P()->generatedMazeWidth(), P()->generatedMazeHeight(), &mazeInterface);
    }

    // Check to see if it's a valid maze
    m_isValidMaze = MazeChecker::isValidMaze(basicMaze);
    if (!m_isValidMaze) {
        L()->warn("The maze failed validation. The mouse algorithm will not execute.");
    }

    // Optionally save the maze
    if (!P()->useMazeFile() && P()->saveGeneratedMaze()) {
        MazeFileType type = STRING_TO_MAZE_FILE_TYPE.at(P()->generatedMazeType());
        std::string mazeFilePath = Directory::getResMazeDirectory() +
            P()->generatedMazeFile() + MAZE_FILE_TYPE_TO_SUFFIX.at(type);
        bool success = MazeFileUtilities::saveMaze(basicMaze, mazeFilePath, type);
        if (success) {
            L()->info("Maze saved to \"%v\".", mazeFilePath);
        }
        else {
            L()->warn("Unable to save maze to \"%v\".", mazeFilePath);
        }
    }

    // Mirror and rotate the maze
    if (P()->mazeMirrored()) {
        basicMaze = mirrorAcrossVertical(basicMaze);
        L()->info("Mirroring the maze across the vertical.");
    }
    for (int i = 0; i < P()->mazeRotations(); i += 1) {
        basicMaze = rotateCounterClockwise(basicMaze);
        L()->info("Rotating the maze counter-clockwise (%vx).", i + 1);
    }

    // Then, store whether or not the maze is an official maze
    m_isOfficialMaze = m_isValidMaze && MazeChecker::isOfficialMaze(basicMaze);
    if (m_isValidMaze && !m_isOfficialMaze) {
        L()->warn("The maze did not pass the \"is official maze\" tests.");
    }

    // Load the maze given by the maze generation algorithm
    m_maze = initializeFromBasicMaze(basicMaze);
}
Exemple #6
0
Main::Main(QCanvas& c, QWidget* parent, const char* name, WFlags f) :
    QMainWindow(parent,name,f),
    canvas(c)
{
    editor = new FigureEditor(canvas,this); // 繼承canvas view而來
    QMenuBar* menu = menuBar();

    QPopupMenu* file = new QPopupMenu( menu ); // 當parent被刪除,則子類別也會被刪除
    file->insertItem("&Fill canvas", this, SLOT(init()), CTRL+Key_F);
    file->insertItem("&Erase canvas", this, SLOT(clear()), CTRL+Key_E);
    file->insertItem("&New view", this, SLOT(newView()), CTRL+Key_N);
    file->insertSeparator();
    file->insertItem("&Print...", this, SLOT(print()), CTRL+Key_P);
    file->insertSeparator();
    file->insertItem("E&xit", qApp, SLOT(quit()), CTRL+Key_Q);
    menu->insertItem("&File", file); // 建立一個工具列名為File的label

    QPopupMenu* edit = new QPopupMenu( menu );
    edit->insertItem("Add &Circle", this, SLOT(addCircle()), ALT+Key_C);
    edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), ALT+Key_H);
    edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), ALT+Key_P);
    edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), ALT+Key_I);
    edit->insertItem("Add &Text", this, SLOT(addText()), ALT+Key_T);
    edit->insertItem("Add &Line", this, SLOT(addLine()), ALT+Key_L);
    edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), ALT+Key_R);
    edit->insertItem("Add &Sprite", this, SLOT(addSprite()), ALT+Key_S);
    edit->insertItem("Create &Mesh", this, SLOT(addMesh()), ALT+Key_M );
    edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), ALT+Key_A);
    menu->insertItem("&Edit", edit);

    QPopupMenu* view = new QPopupMenu( menu );
    view->insertItem("&Enlarge", this, SLOT(enlarge()), SHIFT+CTRL+Key_Plus);
    view->insertItem("Shr&ink", this, SLOT(shrink()), SHIFT+CTRL+Key_Minus);
    view->insertSeparator();
    view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), CTRL+Key_PageDown);
    view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), CTRL+Key_PageUp);
    view->insertItem("&Zoom in", this, SLOT(zoomIn()), CTRL+Key_Plus);
    view->insertItem("Zoom &out", this, SLOT(zoomOut()), CTRL+Key_Minus);
    view->insertItem("Translate left", this, SLOT(moveL()), CTRL+Key_Left);
    view->insertItem("Translate right", this, SLOT(moveR()), CTRL+Key_Right);
    view->insertItem("Translate up", this, SLOT(moveU()), CTRL+Key_Up);
    view->insertItem("Translate down", this, SLOT(moveD()), CTRL+Key_Down);
    view->insertItem("&Mirror", this, SLOT(mirror()), CTRL+Key_Home);
    menu->insertItem("&View", view);

    options = new QPopupMenu( menu );
    dbf_id = options->insertItem("Double buffer", this, SLOT(toggleDoubleBuffer()));
    options->setItemChecked(dbf_id, TRUE);
    menu->insertItem("&Options",options);

    menu->insertSeparator();

    QPopupMenu* help = new QPopupMenu( menu );
    help->insertItem("&About", this, SLOT(help()), Key_F1);
    help->setItemChecked(dbf_id, TRUE); // 很奇怪,當TRUE時,把dbf_id打勾,不懂
    menu->insertItem("&Help",help);

    statusBar();
    // 返回這個窗口的狀態條。如果沒有的話
    // statusBar()會創建一個空的狀態條,並且如果需要也創建一個工具提示組。

    setCentralWidget(editor);

    printer = 0;

    init();
}
Exemple #7
0
CircuitView::CircuitView(CircuitDocument *circuitDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name)
        : ICNView(circuitDocument, viewContainer, viewAreaId, name),
        p_circuitDocument(circuitDocument) {
    KActionCollection *ac = actionCollection();

    new KAction("Dump linear equations", Qt::CTRL | Qt::Key_D, circuitDocument, SLOT(displayEquations()), ac, "dump_les");

    //BEGIN Item Control Actions
    KRadioAction * ra;
    ra = new KRadioAction(i18n("0 Degrees"), "", 0, circuitDocument, SLOT(setOrientation0()), ac, "edit_orientation_0");
    ra->setExclusiveGroup("orientation");
    ra->setChecked(true);
    ra = new KRadioAction(i18n("90 Degrees"), "", 0, circuitDocument, SLOT(setOrientation90()), ac, "edit_orientation_90");
    ra->setExclusiveGroup("orientation");
    ra = new KRadioAction(i18n("180 Degrees"), "", 0, circuitDocument, SLOT(setOrientation180()), ac, "edit_orientation_180");
    ra->setExclusiveGroup("orientation");
    ra = new KRadioAction(i18n("270 Degrees"), "", 0, circuitDocument, SLOT(setOrientation270()), ac, "edit_orientation_270");
    ra->setExclusiveGroup("orientation");

    new KAction(i18n("Create Subcircuit"), "", 0, circuitDocument, SLOT(createSubcircuit()), ac, "circuit_create_subcircuit");
    new KAction(i18n("Rotate Clockwise"), "rotate_cw", "]", circuitDocument, SLOT(rotateClockwise()), ac, "edit_rotate_cw");
    new KAction(i18n("Rotate Counter-Clockwise"), "rotate_ccw", "[", circuitDocument, SLOT(rotateCounterClockwise()), ac, "edit_rotate_ccw");
    new KAction(i18n("Flip Horizontally"), "", 0, circuitDocument, SLOT(flipHorizontally()), ac, "edit_flip_horizontally");
    new KAction(i18n("Flip Vertically"), "", 0, circuitDocument, SLOT(flipVertically()), ac, "edit_flip_vertically");
    //END Item Control Actions

    setXMLFile("ktechlabcircuitui.rc", true);

    QWhatsThis::add(this, i18n(
                        "Construct a circuit by dragging components from the Component selector from the left. Create the connections by dragging a wire from the component connectors.<br><br>"

                        "The simulation is running by default, but can be paused and resumed from the Tools menu.<br><br>"

                        "To delete a wire, select it with a select box, and hit delete.<br><br>"

                        "To edit the attributes of a component, select it (making sure that no components of another type are also selected), and edit in the toolbar. More advanced properties can be edited using the item editor on the right.<br><br>"

                        "Subcircuits can be created by connecting the components with an External Connection, selecting the desired components and clicking on \"Create Subcircuit\" in the right-click menu.")
                   );

    m_pViewIface = new CircuitViewIface(this);

    m_statusBar->insertItem("", ViewStatusBar::SimulationState);
    connect(Simulator::self(), SIGNAL(simulatingStateChanged(bool)), this, SLOT(slotUpdateRunningStatus(bool)));
    slotUpdateRunningStatus(Simulator::self()->isSimulating());
}
Exemple #8
0
void Shutter::manualCounterClockwise(uint16_t turns) {
  rotateCounterClockwise(turns);
}