void CmdPartImportCurveNet::activated(int iMsg) { QStringList filter; filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)"); filter << QObject::tr("STEP (*.stp *.step)"); filter << QObject::tr("IGES (*.igs *.iges)"); filter << QObject::tr("BREP (*.brp *.brep)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { QFileInfo fi; fi.setFile(fn); openCommand("Part Import Curve Net"); doCommand(Doc,"f = App.activeDocument().addObject(\"Part::CurveNet\",\"%s\")", (const char*)fi.baseName().toAscii()); doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); commitCommand(); updateActive(); } }
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 CmdPartDefeaturing::activated(int iMsg) { Q_UNUSED(iMsg); Gui::WaitCursor wc; Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid); openCommand("Defeaturing"); for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) { try { std::string shape; shape.append("sh=App."); shape.append(it->getDocName()); shape.append("."); shape.append(it->getFeatName()); shape.append(".Shape\n"); std::string faces; std::vector<std::string> subnames = it->getSubNames(); for (std::vector<std::string>::iterator sub = subnames.begin(); sub != subnames.end(); ++sub) { faces.append("sh."); faces.append(*sub); faces.append(","); } doCommand(Doc,"\nsh = App.getDocument('%s').%s.Shape\n" "nsh = sh.defeaturing([%s])\n" "if not sh.isPartner(nsh):\n" "\t\tdefeat = App.ActiveDocument.addObject('Part::Feature','Defeatured').Shape = nsh\n" "\t\tGui.ActiveDocument.%s.hide()\n" "else:\n" "\t\tFreeCAD.Console.PrintError('Defeaturing failed\\n')", it->getDocName(), it->getFeatName(), faces.c_str(), it->getFeatName()); } catch (const Base::Exception& e) { Base::Console().Warning("%s: %s\n", it->getFeatName(), e.what()); } } commitCommand(); updateActive(); }
void CmdRaytracingNewPartSegment::activated(int iMsg) { std::vector<Part::Feature*> parts = Gui::Selection().getObjectsOfType<Part::Feature>(); if (parts.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select a Part object.")); return; } std::vector<App::DocumentObject*> pages = App::GetApplication().getActiveDocument() ->getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (pages.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"), QObject::tr("Create a Povray project to insert a view.")); return; } std::string ProjName; if (pages.size() > 1) { pages = Gui::Selection().getObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (pages.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"), QObject::tr("Select a Povray project to insert the view.")); return; } } ProjName = pages.front()->getNameInDocument(); openCommand("Create view"); for (std::vector<Part::Feature*>::iterator it = parts.begin(); it != parts.end(); ++it) { std::string FeatName = (*it)->getNameInDocument(); FeatName += "_View"; FeatName = getUniqueObjectName(FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayFeature','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Color = Gui.activeDocument().%s.ShapeColor",FeatName.c_str(),(*it)->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",ProjName.c_str(), FeatName.c_str()); } updateActive(); commitCommand(); }
void CmdPartSimpleCopy::activated(int iMsg) { Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(partid); openCommand("Create Copy"); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape=" "App.ActiveDocument.%s.Shape\n" "App.ActiveDocument.ActiveObject.Label=" "App.ActiveDocument.%s.Label\n", (*it)->getNameInDocument(), (*it)->getNameInDocument(), (*it)->getNameInDocument()); copyVisual("ActiveObject", "ShapeColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "LineColor", (*it)->getNameInDocument()); copyVisual("ActiveObject", "PointColor", (*it)->getNameInDocument()); } commitCommand(); updateActive(); }
void CmdPointsImport::activated(int iMsg) { QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString::null, QString(), QObject::tr("Ascii Points (*.asc);;All Files (*.*)")); if ( fn.isEmpty() ) return; if (! fn.isEmpty() ) { QFileInfo fi; fi.setFile(fn); openCommand("Points Import Create"); doCommand(Doc,"f = App.ActiveDocument.addObject(\"Points::ImportAscii\",\"%s\")", (const char*)fi.baseName().toAscii()); doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii()); commitCommand(); updateActive(); } }
void CmdPathShape::activated(int iMsg) { std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); if (Sel.size() == 1) { if (Sel[0].pObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature *pcPartObject = dynamic_cast<Part::Feature*>(Sel[0].pObject); std::string FeatName = getUniqueObjectName("PathShape"); openCommand("Create Path Compound"); doCommand(Doc,"FreeCAD.activeDocument().addObject('Path::FeatureShape','%s')",FeatName.c_str()); doCommand(Doc,"FreeCAD.activeDocument().%s.Shape = FreeCAD.activeDocument().%s.Shape.copy()",FeatName.c_str(),pcPartObject->getNameInDocument()); commitCommand(); updateActive(); } else { Base::Console().Error("Exactly one shape object must be selected\n"); return; } } else { Base::Console().Error("Exactly one shape object must be selected\n"); return; } }
void CmdPartShapeFromMesh::activated(int iMsg) { Q_UNUSED(iMsg); bool ok; double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Sewing Tolerance"), QObject::tr("Enter tolerance for sewing shape:"), 0.1, 0.01,10.0,2,&ok); if (!ok) return; Base::Type meshid = Base::Type::fromName("Mesh::Feature"); std::vector<App::DocumentObject*> meshes; meshes = Gui::Selection().getObjectsOfType(meshid); Gui::WaitCursor wc; std::vector<App::DocumentObject*>::iterator it; openCommand("Convert mesh"); for (it = meshes.begin(); it != meshes.end(); ++it) { App::Document* doc = (*it)->getDocument(); std::string mesh = (*it)->getNameInDocument(); std::string name = doc->getUniqueObjectName(mesh.c_str()); doCommand(Doc,"import Part"); doCommand(Doc,"FreeCAD.getDocument(\"%s\").addObject(\"Part::Feature\",\"%s\")" ,doc->getName() ,name.c_str()); doCommand(Doc,"__shape__=Part.Shape()"); doCommand(Doc,"__shape__.makeShapeFromMesh(" "FreeCAD.getDocument(\"%s\").getObject(\"%s\").Mesh.Topology,%f" ")" ,doc->getName() ,mesh.c_str() ,tol); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Shape=__shape__" ,doc->getName() ,name.c_str()); doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").purgeTouched()" ,doc->getName() ,name.c_str()); doCommand(Doc,"del __shape__"); } commitCommand(); }
void CmdPartSimpleCopy::activated(int iMsg) { Q_UNUSED(iMsg); Base::Type partid = Base::Type::fromName("Part::Feature"); std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid); openCommand("Create Copy"); for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) { doCommand(Doc,"App.ActiveDocument.addObject('Part::Feature','%s').Shape=" "App.ActiveDocument.%s.Shape\n" "App.ActiveDocument.ActiveObject.Label=" "App.ActiveDocument.%s.Label\n", it->getFeatName(), it->getFeatName(), it->getFeatName()); copyVisual("ActiveObject", "ShapeColor", it->getFeatName()); copyVisual("ActiveObject", "LineColor", it->getFeatName()); copyVisual("ActiveObject", "PointColor", it->getFeatName()); copyVisual("ActiveObject", "DiffuseColor", it->getFeatName()); } commitCommand(); updateActive(); }
void CmdPartSimpleCylinder::activated(int iMsg) { PartGui::DlgPartCylinderImp dlg(Gui::getMainWindow()); if (dlg.exec()== QDialog::Accepted) { Base::Vector3d dir = dlg.getDirection(); openCommand("Create Part Cylinder"); doCommand(Doc,"from FreeCAD import Base"); doCommand(Doc,"import Part"); doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Feature\",\"Cylinder\")" ".Shape=Part.makeCylinder(%f,%f," "Base.Vector(%f,%f,%f)," "Base.Vector(%f,%f,%f))" ,dlg.radius->value() ,dlg.length->value() ,dlg.xPos->value() ,dlg.yPos->value() ,dlg.zPos->value() ,dir.x,dir.y,dir.z); commitCommand(); updateActive(); doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")"); } }
void CmdRaytracingExportProject::activated(int) { QString filterLabel; unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (n != 1) { n = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId()); if (n != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Raytracing project object.")); return; } else { filterLabel = QString::fromLatin1("%1 (*.lxs)").arg(QObject::tr("Luxrender")); } } else { filterLabel = QString::fromLatin1("%1 (*.pov)").arg(QObject::tr("POV-Ray")); } QStringList filter; filter << filterLabel; filter << QString::fromLatin1("%1 (*.*)").arg(QObject::tr("All Files")); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); openCommand("Raytracing export project"); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); std::string fname = (const char*)fn.toUtf8(); doCommand(Doc,"OutFile = open(unicode('%s','utf-8'),'w')",fname.c_str()); doCommand(Doc,"OutFile.write(PageFile.read())"); doCommand(Doc,"del OutFile,PageFile"); commitCommand(); } }
void CmdPartSection::activated(int iMsg) { unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId()); if (n != 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select two shapes please.")); return; } std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection(); std::string FeatName = getUniqueObjectName("Section"); std::string BaseName = Sel[0].FeatName; std::string ToolName = Sel[1].FeatName; openCommand("Section"); doCommand(Doc,"App.activeDocument().addObject(\"Part::Section\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str()); doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str()); doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str()); doCommand(Gui,"Gui.activeDocument().%s.LineColor = Gui.activeDocument().%s.ShapeColor", FeatName.c_str(),BaseName.c_str()); updateActive(); commitCommand(); }
static int getCommand() { char letra; int i; for ( i= 0; i < SHELL_BUFFER_LENGTH; i++) { shellBuffer[i]=0x00; } index = 0; do{ kprintf("%s",PROMPT); kprintf("%s$ ",shellGetCWD()); do{ letra = getchar(); if( isArrow(letra)) { fetchCommand(letra); } else if ( letra == '\b') { if ( index > 0) { backSpace(); index--; } } else if( letra == '\t') { //autoFill(); } else { shellBuffer[index++] = letra; kprintf("%c",letra); } }while (letra != '\n' && index < MAX_COMM_LENGTH); /*Esta condicion se cumple si solo presiono enter * asi no muestro error y muestro el prompt otra vez */ if( index <= 1 ) index = 0; if(index >= (MAX_COMM_LENGTH - 1)) kprintf("\n"); }while( index == 0); /*Guarda el comando en el historial*/ commitCommand(); /*Recupero la primera palabra del shell y la trato como si fuera un comando*/ getCommandFromPrompt(shellBuffer); /*Recupero los flags, estos son de la forma * -flag * Si no hay flags, recupero los parametros */ if(getFlagsFromPrompt(shellBuffer) == 0) getParamsFromPrompt(shellBuffer,strlen(command)); for ( i = 0; i < COMM_QTY; i++ ) { if ( !strcmp(command,myCommands[i].command)) return myCommands[i].code; } return -1; }
void CmdSketcherToggleConstruction::activated(int iMsg) { // Option A: nothing is selected change creation mode from/to construction if(Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 0){ Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); if (geometryCreationMode == Construction) { geometryCreationMode = Normal; } else { geometryCreationMode = Construction; } rcCmdMgr.updateCommands("ToggleConstruction", static_cast<int>(geometryCreationMode)); } else // there was a selection, so operate in toggle mode. { // get the selection std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select edge(s) from the sketch.")); return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); if (SubNames.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select edge(s) from the sketch.")); return; } // make sure the selected object is the sketch in edit mode const App::DocumentObject* obj = selection[0].getObject(); ViewProviderSketch* sketchView = static_cast<ViewProviderSketch*> (Gui::Application::Instance->getViewProvider(obj)); // undo command open openCommand("Toggle draft from/to draft"); // go through the selected subelements for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ // only handle edges if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; // issue the actual commands to toggle doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),GeoId); } } // finish the transaction and update commitCommand(); updateActive(); // clear the selection (convenience) getSelection().clearSelection(); } }
void CmdSketcherToggleConstruction::activated(int iMsg) { Q_UNUSED(iMsg); // Option A: nothing is selected change creation mode from/to construction if(Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 0){ Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); if (geometryCreationMode == Construction) { geometryCreationMode = Normal; } else { geometryCreationMode = Construction; } rcCmdMgr.updateCommands("ToggleConstruction", static_cast<int>(geometryCreationMode)); } else // there was a selection, so operate in toggle mode. { // get the selection std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); // only one sketch with its subelements are allowed to be selected if (selection.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select edge(s) from the sketch.")); return; } // get the needed lists and objects const std::vector<std::string> &SubNames = selection[0].getSubNames(); if (SubNames.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select edge(s) from the sketch.")); return; } // undo command open openCommand("Toggle draft from/to draft"); // go through the selected subelements for (std::vector<std::string>::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ // only handle edges if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1; // issue the actual commands to toggle doCommand(Doc,"App.ActiveDocument.%s.toggleConstruction(%d) ",selection[0].getFeatName(),GeoId); } } // finish the transaction and update commitCommand(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool autoRecompute = hGrp->GetBool("AutoRecompute",false); if(autoRecompute) // toggling does not modify the DoF of the solver, however it may affect features depending on the sketch Gui::Command::updateActive(); // clear the selection (convenience) getSelection().clearSelection(); } }
void CmdPartRuledSurface::activated(int iMsg) { bool ok = false; TopoDS_Shape curve1, curve2; std::string link1, link2, obj1, obj2; Gui::SelectionFilter edgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..2"); Gui::SelectionFilter wireFilter ("SELECT Part::Feature SUBELEMENT Wire COUNT 1..2"); Gui::SelectionFilter partFilter ("SELECT Part::Feature COUNT 2"); bool matchEdge = edgeFilter.match(); bool matchWire = wireFilter.match(); if (matchEdge || matchWire) { // get the selected object const std::vector<Gui::SelectionObject>& result = matchEdge ? edgeFilter.Result[0] : wireFilter.Result[0]; // two edges from one object if (result.size() == 1) { const Part::Feature* part = static_cast<const Part::Feature*>(result[0].getObject()); const std::vector<std::string>& edges = result[0].getSubNames(); if (edges.size() != 2) { ok = false; } else { ok = true; // get the selected sub-shapes const Part::TopoShape& shape = part->Shape.getValue(); curve1 = shape.getSubShape(edges[0].c_str()); curve2 = shape.getSubShape(edges[1].c_str()); obj1 = result[0].getObject()->getNameInDocument(); link1 = edges[0]; obj2 = result[0].getObject()->getNameInDocument(); link2 = edges[1]; } } // two objects and one edge per object else if (result.size() == 2) { const Part::Feature* part1 = static_cast<const Part::Feature*>(result[0].getObject()); const std::vector<std::string>& edges1 = result[0].getSubNames(); const Part::Feature* part2 = static_cast<const Part::Feature*>(result[1].getObject()); const std::vector<std::string>& edges2 = result[1].getSubNames(); if (edges1.size() != 1 || edges2.size() != 1) { ok = false; } else { ok = true; const Part::TopoShape& shape1 = part1->Shape.getValue(); curve1 = shape1.getSubShape(edges1[0].c_str()); const Part::TopoShape& shape2 = part2->Shape.getValue(); curve2 = shape2.getSubShape(edges2[0].c_str()); obj1 = result[0].getObject()->getNameInDocument(); link1 = edges1[0]; obj2 = result[1].getObject()->getNameInDocument(); link2 = edges2[0]; } } } else if (partFilter.match()) { const std::vector<Gui::SelectionObject>& result = partFilter.Result[0]; const Part::Feature* part1 = static_cast<const Part::Feature*>(result[0].getObject()); const Part::Feature* part2 = static_cast<const Part::Feature*>(result[1].getObject()); const Part::TopoShape& shape1 = part1->Shape.getValue(); curve1 = shape1._Shape; const Part::TopoShape& shape2 = part2->Shape.getValue(); curve2 = shape2._Shape; obj1 = part1->getNameInDocument(); obj2 = part2->getNameInDocument(); if (!curve1.IsNull() && !curve2.IsNull()) { if (curve1.ShapeType() == TopAbs_EDGE && curve2.ShapeType() == TopAbs_EDGE) ok = true; if (curve1.ShapeType() == TopAbs_WIRE && curve2.ShapeType() == TopAbs_WIRE) ok = true; } } if (!ok) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("You have to select either two edges or two wires.")); return; } openCommand("Create ruled surface"); doCommand(Doc, "FreeCAD.ActiveDocument.addObject('Part::RuledSurface','Filled shape')"); doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.Curve1=(FreeCAD.ActiveDocument.%s,['%s'])" ,obj1.c_str(), link1.c_str()); doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.Curve2=(FreeCAD.ActiveDocument.%s,['%s'])" ,obj2.c_str(), link2.c_str()); commitCommand(); updateActive(); }
void CmdRaytracingRender::activated(int iMsg) { // determining render type Base::Type renderType; unsigned int n1 = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); if (n1 != 1) { unsigned int n2 = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId()); if (n2 != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Raytracing project object.")); return; } else { renderType = Raytracing::LuxProject::getClassTypeId(); } } else { renderType = Raytracing::RayProject::getClassTypeId(); } // checking if renderer is present ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing"); std::string renderer; if (renderType == Raytracing::RayProject::getClassTypeId()) { renderer = hGrp->GetASCII("PovrayExecutable", ""); if (renderer == "") { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray not found"), QObject::tr("Please set the path to the POV-Ray executable in the preferences.")); return; } else { QFileInfo fi(QString::fromUtf8(renderer.c_str())); if (!fi.exists() || !fi.isFile()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray not found"), QObject::tr("Please correct the path to the POV-Ray executable in the preferences.")); return; } } } else { renderer = hGrp->GetASCII("LuxrenderExecutable", ""); if (renderer == "") { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Luxrender not found"), QObject::tr("Please set the path to the luxrender or luxconsole executable in the preferences.")); return; } else { QFileInfo fi(QString::fromUtf8(renderer.c_str())); if (!fi.exists() || !fi.isFile()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Luxrender not found"), QObject::tr("Please correct the path to the luxrender or luxconsole executable in the preferences.")); return; } } } std::vector<Gui::SelectionObject> Sel = getSelection().getSelectionEx(0, renderType); if (renderType == Raytracing::RayProject::getClassTypeId()) { Raytracing::RayProject* proj = static_cast<Raytracing::RayProject*>(Sel[0].getObject()); QFileInfo fi(QString::fromUtf8(proj->PageResult.getValue())); if (!fi.exists() || !fi.isFile()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("POV-Ray file missing"), QObject::tr("The POV-Ray project file doesn't exist.")); return; } QStringList filter; #ifdef FC_OS_WIN32 filter << QObject::tr("Rendered image (*.bmp *.png)"); #else filter << QObject::tr("Rendered image (*.png)"); #endif filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Rendered image"), QString(), filter.join(QLatin1String(";;"))); if (!fn.isEmpty()) { fn = QDir::toNativeSeparators(fn); #ifdef FC_OS_WIN32 fn.replace(QLatin1String("\\"), QLatin1String("\\\\")); #endif std::string fname = (const char*)fn.toUtf8(); openCommand("Render project"); int width = hGrp->GetInt("OutputWidth", 800); std::stringstream w; w << width; int height = hGrp->GetInt("OutputHeight", 600); std::stringstream h; h << height; std::string par = hGrp->GetASCII("OutputParameters", "+P +A"); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].getFeatName()); doCommand(Doc,"import subprocess,tempfile"); doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]"); doCommand(Doc,"f = open(TempFile,'wb')"); doCommand(Doc,"f.write(PageFile.read())"); doCommand(Doc,"f.close()"); #ifdef FC_OS_WIN32 // http://povray.org/documentation/view/3.6.1/603/ doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" /EXIT /RENDER '+TempFile)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); #else doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); #endif doCommand(Gui,"import ImageGui"); doCommand(Gui,"ImageGui.open('%s')",fname.c_str()); doCommand(Doc,"del TempFile,PageFile"); commitCommand(); } } else { Raytracing::LuxProject* proj = static_cast<Raytracing::LuxProject*>(Sel[0].getObject()); QFileInfo fi(QString::fromUtf8(proj->PageResult.getValue())); if (!fi.exists() || !fi.isFile()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Lux project file missing"), QObject::tr("The Lux project file doesn't exist.")); return; } openCommand("Render project"); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].getFeatName()); doCommand(Doc,"import subprocess,tempfile"); doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.lxs')[1]"); doCommand(Doc,"f = open(TempFile,'wb')"); doCommand(Doc,"f.write(PageFile.read())"); doCommand(Doc,"f.close()"); doCommand(Doc,"subprocess.Popen([\"%s\",TempFile])",renderer.c_str()); doCommand(Doc,"del TempFile,PageFile"); commitCommand(); } }
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; } }