MainWindow2::MainWindow2( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::MainWindow2 ) { ui->setupUi( this ); m_object = new Object(); m_object->defaultInitialisation(); editor = new Editor( this ); m_pScribbleArea = editor->getScribbleArea(); m_pTimeLine = new TimeLine( this, editor ); makeTimeLineConnections(); arrangePalettes(); createMenus(); loadAllShortcuts(); // must run after 'arragePalettes' editor->setObject( m_object ); editor->resetUI(); readSettings(); makeColorPaletteConnections(); makeColorWheelConnections(); connect(editor, SIGNAL(needSave()), this, SLOT(saveDocument())); connect(m_pToolSet, SIGNAL(clearButtonClicked()), editor, SLOT(clearCurrentFrame())); connect(editor, SIGNAL(changeTool(ToolType)), m_pToolSet, SLOT(setCurrentTool(ToolType))); editor->setCurrentLayer( this->editor->m_pObject->getLayerCount() - 1 ); }
QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent) : AbstractViewInspector(parent), data(new QDeclarativeViewInspectorPrivate(this)) { data->view = view; data->manipulatorLayer = new LiveLayerItem(view->scene()); data->selectionTool = new LiveSelectionTool(this); data->zoomTool = new ZoomTool(this); data->colorPickerTool = new ColorPickerTool(this); data->boundingRectHighlighter = new BoundingRectHighlighter(this); setCurrentTool(data->selectionTool); // to capture ChildRemoved event when viewport changes data->view->installEventFilter(this); data->setViewport(data->view->viewport()); connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), this, SLOT(sendColorChanged(QColor))); changeTool(InspectorProtocol::SelectTool); }
/** * Handler for mouse release events. * Mouse tracking is disabled and the position of the cursor set. * The events are delivered to the specific methods, depending on where the * cursor was released, and the current association or widget cleaned. * Finally, the current tool is changed if needed. * * @param ome The received event. */ void ToolBarState::mouseRelease(UMLSceneMouseEvent* ome) { setMouseEvent(ome, QEvent::MouseButtonRelease); // Set the position of the mouse // TODO, should only be available in this state? m_pUMLScene->setPos(m_pMouseEvent->pos()); m_pUMLScene->viewport()->setMouseTracking(false); if (getCurrentWidget()) { mouseReleaseWidget(); setCurrentWidget(0); } else if (getCurrentAssociation()) { mouseReleaseAssociation(); setCurrentAssociation(0); } else { mouseReleaseEmpty(); } // Default, rightbutton changes the tool. // The arrow tool overrides the changeTool() function. changeTool(); }
GCodeExport::GCodeExport(char *outputfile, PathContur *contur1, PathContur *contur2, Mode mode, double depth, double edgedepth, \ double zsafe, int millingSpeed, int edgeMillingSpeed, int spindleRpm, double millingDiameter, \ DrillReader *drillReader, int drillingSpeed, int drillingLiftSpeed, int drillingSpindleSpeed, \ double drillDepth, double drillZSafe, bool sameDiameter , bool isProbe, double filamentDiameter, \ double nozzleDiameter, int extruderTemperature, double printingSpeed, bool edges, double laserEnergy, \ double toolXOffset, double toolYOffset) { totalTime = 0.0L; filamentUsed = 0.0L; char lineBuffer[1024]; if(contur1==0) { totalTime = -1.0L; return; } if(contur1->first()==0) { totalTime = -1.0L; return; } FILE *fl = fopen(outputfile, "w"); if(fl==0) { totalTime = -1.0L; return; } double firstTime = 0.0L; double firstFilament = 0.0L; const double filamentMMPerHeadMM = nozzleDiameter*nozzleDiameter/(filamentDiameter*filamentDiameter); // writing gcode headers fputs("%\nG90G40G17G21\n", fl); switch (mode) { case Milling: if(isProbe) { fputs("G30 (probe Z)\n", fl); } fputs("G92 (set founded Z as zero)\n", fl); sprintf(lineBuffer, "G00Z%f\n", zsafe); fputs(lineBuffer, fl); headPosition = GPoint(0.0L,0.0L); headZPosition = zsafe; sprintf(lineBuffer, "M03S%d\nG04P%d\n", spindleRpm, spindleRpm/5); // start spindle and wait fputs(lineBuffer, fl); doShapes(fl, mode, contur1->first(), millingDiameter, zsafe, depth, millingSpeed, filamentMMPerHeadMM, laserEnergy); if(edges) { fputs("(Cutting edges)\n", fl); doShapes(fl, mode, contur1->edges(), millingDiameter, zsafe, edgedepth, edgeMillingSpeed, filamentMMPerHeadMM, laserEnergy); fputs("(Cutting edges done)\n", fl); } fputs("M5\n", fl); doDrill(fl, true, drillReader, drillZSafe, sameDiameter, isProbe, drillingSpeed, drillingLiftSpeed, drillingSpindleSpeed, drillDepth, zsafe); if(contur2) { if(contur2->first()) { fputs("G28 (Parking)\n", fl); headZPosition = zsafe; changeTool(fl, millingDiameter, zsafe, zsafe, true, isProbe, (char*)"Insert milling tool and turn board", false); sprintf(lineBuffer, "M03S%d\nG04P%d\n", spindleRpm, spindleRpm/5); // start spindle and wait fputs(lineBuffer, fl); doShapes(fl, mode, contur2->first(), millingDiameter, zsafe, depth, millingSpeed, filamentMMPerHeadMM, laserEnergy); } } break; case Printing: fputs("G92\n", fl); sprintf(lineBuffer, "G00Z%f\n", zsafe); fputs(lineBuffer, fl); headPosition = GPoint(0.0L,0.0L); headZPosition = zsafe; doShapes(fl, mode, contur1->first(), millingDiameter, zsafe, 0.0f, printingSpeed, filamentMMPerHeadMM, laserEnergy); sprintf(lineBuffer, "G00X%fY%f (Switch to tools coords)\nG92\n", toolXOffset, toolYOffset); // change coords to tool mode fputs(lineBuffer, fl); doDrill(fl, true, drillReader, drillZSafe, sameDiameter, isProbe, drillingSpeed, drillingLiftSpeed, drillingSpindleSpeed, drillDepth, zsafe); if(edges) { changeTool(fl, millingDiameter, drillZSafe, zsafe, true, isProbe, (char*)"Insert milling tool", true); sprintf(lineBuffer, "M03S%d\nG04P%d\n", spindleRpm, spindleRpm/5); // start spindle and wait fputs(lineBuffer, fl); fputs("(Cutting edges)\n", fl); doShapes(fl, Milling, contur1->edges(), millingDiameter, zsafe, edgedepth, edgeMillingSpeed, filamentMMPerHeadMM, laserEnergy); fputs("M5\n", fl); fputs("(Cutting edges done)\n", fl); } if(contur2) { if(contur2->first()) { moveHeadTo(fl,mode, GPoint(0.0L, 0.0L), zsafe); fputs("(Remove milling tool, turn board, prepare pen position manually)\n", fl); firstTime = totalTime; firstFilament = filamentUsed; fl = organizeSecondFile(fl, outputfile, false); if(fl==0) { totalTime = -1.0L; return; } headPosition = GPoint(0.0L,0.0L); headZPosition = 0.0L; doShapes(fl, mode, contur2->first(), millingDiameter, zsafe, 0.0f, printingSpeed, filamentMMPerHeadMM, laserEnergy); } } break; case Extrudering: sprintf(lineBuffer, "M109S%d ; wait temperaturen\n", extruderTemperature); fputs(lineBuffer, fl); fputs("M82\n", fl); fputs("G92 (set all axis to zero)\n", fl); headPosition = GPoint(0.0L,0.0L); headZPosition = 0.0L; ePosition = 0.0L; fputs("(Start clean extruder)\n", fl); doShapes(fl, mode, contur1->edges(), nozzleDiameter, zsafe, 0.0f, printingSpeed, filamentMMPerHeadMM, laserEnergy); fputs("(Extruder cleaning done)\n", fl); doShapes(fl, mode, contur1->first(), nozzleDiameter, zsafe, 0.0f, printingSpeed, filamentMMPerHeadMM, laserEnergy); sprintf(lineBuffer, "G00X%fY%f (Switch to tools coords)\nG92\n", toolXOffset, toolYOffset); // change coords to tool mode fputs(lineBuffer, fl); doDrill(fl, true, drillReader, drillZSafe, sameDiameter, isProbe, drillingSpeed, drillingLiftSpeed, drillingSpindleSpeed, drillDepth, zsafe); if(edges) { changeTool(fl, millingDiameter, drillZSafe, zsafe, true, isProbe, (char*)"Insert milling tool", true); sprintf(lineBuffer, "M03S%d\nG04P%d\n", spindleRpm, spindleRpm/5); // start spindle and wait fputs(lineBuffer, fl); fputs("(Cutting edges)\n", fl); doShapes(fl, Milling, contur1->edges(), millingDiameter, zsafe, edgedepth, edgeMillingSpeed, filamentMMPerHeadMM, laserEnergy); fputs("M5\n", fl); fputs("(Cutting edges done)\n", fl); } if(contur2) { if(contur2->first()) { moveHeadTo(fl,mode, GPoint(0.0L, 0.0L), zsafe); fputs("(Turn board, set head Z positon manualy and run second file)\n", fl); firstTime = totalTime; firstFilament = filamentUsed; fl = organizeSecondFile(fl, outputfile, true); if(fl==0) { totalTime = -1.0L; return; } headPosition = GPoint(0.0L,0.0L); headZPosition = 0.0L; doShapes(fl, mode, contur2->first(), millingDiameter, zsafe, 0.0f, millingSpeed, filamentMMPerHeadMM, laserEnergy); } } break; case Lasering: fputs("G92 (set founded Z as zero)\n", fl); headPosition = GPoint(0.0L,0.0L); headZPosition = 0.0f; doShapes(fl, mode, contur1->first(), millingDiameter, 0.0f, depth, printingSpeed, filamentMMPerHeadMM, laserEnergy); sprintf(lineBuffer, "G00X%fY%f (Switch to tools coords)\nG92\n", toolXOffset, toolYOffset); // change coords to tool mode fputs(lineBuffer, fl); doDrill(fl, false, drillReader, drillZSafe, sameDiameter, isProbe, drillingSpeed, drillingLiftSpeed, drillingSpindleSpeed, drillDepth, 0.0f); if(edges) { changeTool(fl, millingDiameter, drillZSafe, zsafe, true, isProbe, (char*)"Insert milling tool", true); sprintf(lineBuffer, "M03S%d\nG04P%d\n", spindleRpm, spindleRpm/5); // start spindle and wait fputs(lineBuffer, fl); fputs("(Cutting edges)\n", fl); doShapes(fl, Milling, contur1->edges(), millingDiameter, zsafe, edgedepth, edgeMillingSpeed, filamentMMPerHeadMM, laserEnergy); fputs("M5\n", fl); fputs("(Cutting edges done)\n", fl); } fputs("G28 (Parking)\nM0 (Turn board)\n", fl); sprintf(lineBuffer, "G00X%fY%f (Switch to laser coords)\nG92\n",-toolXOffset, -toolYOffset); // change coords to laser mode fputs(lineBuffer, fl); headPosition = GPoint(0.0L,0.0L); headZPosition = 0.0f; if(contur2) if(contur2->first()) doShapes(fl, mode, contur2->first(), millingDiameter, 0.0f, depth, printingSpeed, filamentMMPerHeadMM, laserEnergy); break; } fputs("G28 (parking)\n", fl); fputs("M30\n", fl); putFooterComments(fl, mode==Extrudering); totalTime += firstTime; filamentUsed += firstFilament; fclose(fl); }
void GCodeExport::doDrill(FILE *fl, bool changeToDrill, DrillReader *drillReader, double drillZSafe, bool sameDiameter, bool isProbe, int drillingSpeed, \ int drillingLiftSpeed, int drillingSpindleSpeed, double drillDepth, double zsafe) { char lineBuffer[1024]; // drilling if(drillReader) { if(drillReader->firstDrill()) { toolNumber = 1; if(changeToDrill) changeTool(fl, drillReader->firstDrill()->diameter, zsafe, drillZSafe, sameDiameter, isProbe, (char*)"Drill",true); else if(isProbe) probe(fl, drillZSafe); sprintf(lineBuffer, "M03S%d\nG04P%d\n", drillingSpindleSpeed, drillingSpindleSpeed/5); // start spindle and wait fputs(lineBuffer, fl); Drill *nextDrill = drillReader->firstDrill(); if(sameDiameter || !changeToDrill) { sprintf(lineBuffer,"(Drill %f)\n", nextDrill->diameter); fputs(lineBuffer, fl); } while(nextDrill) { GPoint *next = nextDrill->firstPoint; while(next) { next->used = false; next = next->next; } while(true) { GPoint *closestPoint = 0; double closestDistance = FLT_MAX; next = nextDrill->firstPoint; double tmp; while(next) { if(!next->used){ if( (tmp=next->distance(headPosition))<closestDistance) { closestDistance = tmp; closestPoint = next; } } next = next->next; } if(closestPoint) { drill(fl, *closestPoint, drillDepth, drillingSpeed, drillingLiftSpeed, drillZSafe); closestPoint->used = true; } else { break; // goto from while } } nextDrill = nextDrill->next; if(nextDrill) { if(!sameDiameter) { fputs("M5\n", fl); changeTool(fl, nextDrill->diameter, drillZSafe, drillZSafe, sameDiameter, isProbe, (char*)"Drill", true); sprintf(lineBuffer, "M03S%d\nG04P%d\n", drillingSpindleSpeed, drillingSpindleSpeed/5); // start spindle and wait fputs(lineBuffer, fl); } else { sprintf(lineBuffer,"(Drill %f)\n", nextDrill->diameter); fputs(lineBuffer, fl); } } } fputs("M5\n", fl); } } }
bool UI_SDL::doToolEvents(SDL_Event e) { SDL_Point p; switch (e.type) { case SDL_MOUSEMOTION: p.x = e.motion.x; p.y = e.motion.y; switch(currtool) { case T_Circle: dragMesh.clear(); //If a center has been picked, draw the temp circle if(toolstate == 1) { Vect4 delta = screenToWorld(p) - clicks[0]; double mag = delta.magnitude(); dragMesh.genPrimCircle(clicks[0], mag); } break; case T_Line: dragMesh.clear(); //If a center has been picked, draw the temp circle if(toolstate == 1) { Vect4 end = screenToWorld(p); dragMesh.genPrimEdge(clicks[0], end); } break; case T_Hermite: dragMesh.clear(); if(toolstate >= 1) { Vect4 v[4]; Vect4 curr = screenToWorld(p); if(toolstate == 1) { dragMesh.genPrimEdge(clicks[0], curr); } else { dragMesh.genPrimEdge(clicks[0], clicks[1]); if(toolstate == 3) { dragMesh.genPrimEdge(clicks[2], curr); dragMesh.genPrimHermite( clicks[0], clicks[2], clicks[1], curr); } } } break; case T_Bezier: dragMesh.clear(); if(toolstate >= 1) { Vect4 v[4]; Vect4 curr = screenToWorld(p); if(toolstate == 1) { dragMesh.genPrimEdge(clicks[0], curr); } else { dragMesh.genPrimEdge(clicks[0], clicks[1]); if(toolstate == 3) { dragMesh.genPrimEdge(clicks[2], curr); dragMesh.genPrimBezier( clicks[0], clicks[1], curr, clicks[2]); } } } break; case T_Box: dragMesh.clear(); //If a start point has been picked, draw the temp box if(toolstate == 1) { Vect4 end = screenToWorld(p); dragMesh.genPrimBox(end[0], end[1], end[1]); } break; case T_Sphere: dragMesh.clear(); //If a center has been picked, draw the temp sphere if(toolstate == 1) { Vect4 delta = screenToWorld(p) - clicks[0]; double mag = delta.magnitude(); dragMesh.genPrimSphere(mag); } break; case T_Torus: dragMesh.clear(); //If a start point has been picked, draw the temp torus if(toolstate == 1) { Vect4 end = screenToWorld(p); dragMesh.genPrimTorus(std::abs(end[0]), std::abs(end[1])); } break; default: break; } break; case SDL_MOUSEBUTTONDOWN: p.x = e.button.x; p.y = e.button.y; switch(currtool) { //keep track of the starting click case T_Circle: case T_Line: case T_Box: case T_Sphere: case T_Torus: //All of these just store the start point clicks[0] = screenToWorld(p); toolstate = 1; break; case T_Hermite: if(toolstate == 0 || toolstate == 2) { clicks[toolstate] = screenToWorld(p); toolstate++; } else { std::cerr << "ERR in mousedown Hermite\n"; } break; case T_Bezier: if(toolstate == 0 || toolstate == 2) { clicks[toolstate] = screenToWorld(p); toolstate++; } else { std::cerr << "ERR in mousedown Bezier\n"; } break; default: break; } break; case SDL_MOUSEBUTTONUP: switch(currtool) { case T_Circle: case T_Line: case T_Sphere: case T_Box: case T_Torus: //Make it so if(toolstate == 1) { world->addMesh(new Mesh(dragMesh)); dragMesh.clear(); toolstate = 0; } break; case T_Hermite: if(toolstate == 1 || toolstate == 3) { SDL_Point p; p.x = e.button.x; p.y = e.button.y; clicks[toolstate] = screenToWorld(p); toolstate++; } else { std::cerr << "ERR in mouseup Hermite\n"; } if(toolstate == 4) { //finished dragMesh.clear(); dragMesh.genPrimHermite( clicks[0], clicks[2], clicks[1], clicks[3]); world->addMesh(new Mesh(dragMesh)); dragMesh.clear(); toolstate = 0; } break; case T_Bezier: if(toolstate == 1 || toolstate == 3) { SDL_Point p; p.x = e.button.x; p.y = e.button.y; clicks[toolstate] = screenToWorld(p); toolstate++; } else { std::cerr << "ERR in mouseup Bezier\n"; } if(toolstate == 4) { //finished dragMesh.clear(); dragMesh.genPrimBezier( clicks[0], clicks[1], clicks[3], clicks[2]); world->addMesh(new Mesh(dragMesh)); dragMesh.clear(); toolstate = 0; } break; default: break; } break; case SDL_KEYDOWN: switch(e.key.keysym.sym) { case SDLK_RIGHTBRACKET: changeTool(1); break; case SDLK_LEFTBRACKET: changeTool(-1); break; default: return false; } break; case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_ENTER: //uistate.mouseinwindow = 1; case SDL_WINDOWEVENT_LEAVE: //uistate.mouseinwindow = 0; break; } return false; break; default: return false; } return true; }
/** * Mouse / Pen down / touch start */ bool InputSequence::actionStart(guint32 time) { XOJ_CHECK_TYPE(InputSequence); this->eventTime = time; inputHandler->focusWidget(); checkCanStartInput(); if (!inputRunning) { return false; } // none button release event was sent, send one now // only for this device, other devices may still have unfinished input if (currentInputPage) { PositionInputData pos = getInputDataRelativeToCurrentPage(currentInputPage); currentInputPage->onButtonReleaseEvent(pos); } // Change the tool depending on the key or device if (changeTool()) { return true; } GtkXournal* xournal = inputHandler->getXournal(); // hand tool don't change the selection, so you can scroll e.g. // with your touchscreen without remove the selection ToolHandler* h = inputHandler->getToolHandler(); if (h->getToolType() == TOOL_HAND) { XournalppCursor* cursor = xournal->view->getCursor(); cursor->setMouseDown(true); inScrolling = true; // set reference lastMousePositionX = rootX; lastMousePositionY = rootY; return true; } else if (xournal->selection) { EditSelection* selection = xournal->selection; XojPageView* view = selection->getView(); PositionInputData pos = getInputDataRelativeToCurrentPage(view); CursorSelectionType selType = selection->getSelectionTypeForPos(pos.x, pos.y, xournal->view->getZoom()); if (selType) { if (selType == CURSOR_SELECTION_MOVE && button == 3) { selection->copySelection(); } xournal->view->getCursor()->setMouseDown(true); xournal->selection->mouseDown(selType, pos.x, pos.y); return true; } else { xournal->view->clearSelection(); if (changeTool()) { return true; } } } XojPageView* pv = getPageAtCurrentPosition(); current_view = pv; if (pv) { currentInputPage = pv; PositionInputData pos = getInputDataRelativeToCurrentPage(pv); return pv->onButtonPressEvent(pos); } // not handled return false; }
/** * Mouse / Pen / Touch move */ bool InputSequence::actionMoved(guint32 time) { XOJ_CHECK_TYPE(InputSequence); GtkXournal* xournal = inputHandler->getXournal(); ToolHandler* h = inputHandler->getToolHandler(); this->eventTime = time; changeTool(); if (xournal->view->getControl()->getWindow()->isGestureActive()) { return false; } if (h->getToolType() == TOOL_HAND) { if (inScrolling) { handleScrollEvent(); return true; } return false; } else if (xournal->selection) { EditSelection* selection = xournal->selection; XojPageView* view = selection->getView(); PositionInputData pos = getInputDataRelativeToCurrentPage(view); if (xournal->selection->isMoving()) { selection->mouseMove(pos.x, pos.y); } else { CursorSelectionType selType = selection->getSelectionTypeForPos(pos.x, pos.y, xournal->view->getZoom()); xournal->view->getCursor()->setMouseSelectionType(selType); } return true; } XojPageView* pv = NULL; if (current_view) { pv = current_view; } else { pv = getPageAtCurrentPosition(); } xournal->view->getCursor()->setInsidePage(pv != NULL); if (pv && inputRunning) { // allow events only to a single page! if (currentInputPage == NULL || pv == currentInputPage) { PositionInputData pos = getInputDataRelativeToCurrentPage(pv); return pv->onMotionNotifyEvent(pos); } } return false; }