void CmdRaytracingResetCamera::activated(int iMsg) { std::vector<App::DocumentObject*> sel = getSelection().getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (sel.size() != 1) { sel = getSelection().getObjectsOfType(Raytracing::LuxProject::getClassTypeId()); if (sel.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Raytracing project object.")); return; } } if (sel.front()->getTypeId().isDerivedFrom(Raytracing::RayProject::getClassTypeId())) { //povray try { openCommand("Reset Raytracing Camera"); doCommand(Doc,"import RaytracingGui"); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",sel.front()->getNameInDocument()); commitCommand(); updateActive(); } catch (...) { abortCommand(); throw; } } else if (sel.front()->getTypeId().isDerivedFrom(Raytracing::LuxProject::getClassTypeId())) { //luxrender try { openCommand("Reset Raytracing Camera"); doCommand(Doc,"import RaytracingGui"); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",sel.front()->getNameInDocument()); commitCommand(); updateActive(); } catch (...) { abortCommand(); throw; } } }
/* MME_AbortCommand() * Attempt to abort a submitted command */ MME_ERROR MME_AbortCommand (MME_TransformerHandle_t handle, MME_CommandId_t cmdId) { MME_ERROR res = MME_INTERNAL_ERROR; mme_transformer_t *transformer; /* * Sanity check the arguments */ if (mme_state == NULL) { res = MME_DRIVER_NOT_INITIALIZED; goto error; } MME_PRINTF(MME_DBG_COMMAND, "handle 0x%x cmdId 0x%x\n", handle, cmdId); if (handle == 0 || cmdId == 0) { res = MME_INVALID_HANDLE; goto error; } /* Lookup the transformer instance (takes lock on success) */ transformer = mme_transformer_instance(handle); if (transformer == NULL) { res = MME_INVALID_HANDLE; goto error; } res = abortCommand(transformer, cmdId); _ICS_OS_MUTEX_RELEASE(&transformer->tlock); if (res != MME_SUCCESS) goto error; MME_PRINTF(MME_DBG_COMMAND, "transformer %p Successfully aborted CmdId 0x%x\n", transformer, cmdId); return MME_SUCCESS; error: MME_EPRINTF(MME_DBG_INIT, "Failed : %s (%d)\n", MME_Error_Str(res), res); return res; }
void CmdRaytracingNewLuxProject::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the luxrender image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } std::string FeatName = getUniqueObjectName("LuxProject"); Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(getAction()); QAction* a = pcAction->actions()[iMsg]; QFileInfo tfi(a->property("Template").toString()); if (tfi.isReadable()) { try { openCommand("Create LuxRender project"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8()); doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str()); commitCommand(); } catch (...) { abortCommand(); throw; } } else { QMessageBox::critical(Gui::getMainWindow(), qApp->translate("CmdRaytracingNewLuxProject","No template"), qApp->translate("CmdRaytracingNewLuxProject","No template available")); } }
void UndoStack::endCommand() throw (Exception) { Q_ASSERT(mCurrentIndex == mCommands.count()); if (!mCommandActive) throw LogicError(__FILE__, __LINE__, QString(), tr("No command active!")); if (mCommands.last()->getChildCount() == 0) { // the last command is empty --> remove it from the stack! abortCommand(); return; } mCommandActive = false; // emit signals emit canUndoChanged(canUndo()); emit commandEnded(); }
void UndoStack::clear() noexcept { if (mCommands.isEmpty()) return; if (mCommandActive) try {abortCommand();} catch (...) {} // delete all commands in the stack from top to bottom (newest first, oldest last)! while (!mCommands.isEmpty()) delete mCommands.takeLast(); mCurrentIndex = 0; mCleanIndex = 0; mCommandActive = false; // emit signals emit undoTextChanged(tr("Undo")); emit redoTextChanged(tr("Redo")); emit canUndoChanged(false); emit canRedoChanged(false); emit cleanChanged(true); }
void CmdRaytracingWriteView::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the POV-Ray image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } QStringList filter; filter << QObject::tr("POV-Ray(*.pov)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); if (fn.isEmpty()) return; std::string cFullName = (const char*)fn.toUtf8(); // get all objects of the active document std::vector<Part::Feature*> DocObjects = getActiveGuiDocument()->getDocument()-> getObjectsOfType<Part::Feature>(); openCommand("Write view"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"OutFile = open(unicode(\"%s\",\"utf-8\"),\"w\")",cFullName.c_str()); try { doCommand(Doc,"result = open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read()"); doCommand(Doc,"content = ''"); doCommand(Doc,"content += RaytracingGui.povViewCamera()"); // go through all document objects for (std::vector<Part::Feature*>::const_iterator it=DocObjects.begin();it!=DocObjects.end();++it) { Gui::ViewProvider* vp = getActiveGuiDocument()->getViewProvider(*it); if (vp && vp->isVisible()) { App::PropertyColor *pcColor = dynamic_cast<App::PropertyColor *>(vp->getPropertyByName("ShapeColor")); App::Color col = pcColor->getValue(); doCommand(Doc,"content += Raytracing.getPartAsPovray('%s',App.activeDocument().%s.Shape,%f,%f,%f)", (*it)->getNameInDocument(),(*it)->getNameInDocument(),col.r,col.g,col.b); } } doCommand(Doc,"result = result.replace('//RaytracingContent',content)"); doCommand(Doc,"OutFile.write(result)"); doCommand(Doc,"OutFile.close()"); doCommand(Doc,"del OutFile"); commitCommand(); } catch (...) { doCommand(Doc,"OutFile.close()"); doCommand(Doc,"del OutFile"); abortCommand(); throw; } }