Workbench::Workbench() { // Tree view Gui::DockWindow* tree = new Gui::DockWindow(0, Gui::getMainWindow()); tree->setWindowTitle(QString::fromLatin1("Tree view")); Gui::TreeView* treeWidget = new Gui::TreeView(tree); treeWidget->setRootIsDecorated(false); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); treeWidget->setIndentation(hGrp->GetInt("Indentation", treeWidget->indentation())); QGridLayout* pLayout = new QGridLayout(tree); pLayout->setSpacing(0); pLayout->setMargin (0); pLayout->addWidget(treeWidget, 0, 0); tree->setObjectName (QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Tree view (MVC)"))); tree->setMinimumWidth(210); Gui::DockWindowManager* pDockMgr = Gui::DockWindowManager::instance(); pDockMgr->registerDockWindow("Std_TreeViewMVC", tree); }
void MacroCommand::load() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Macro"); if (hGrp->HasGroup("Macros")) { hGrp = hGrp->GetGroup("Macros"); std::vector<Base::Reference<ParameterGrp> > macros = hGrp->GetGroups(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = macros.begin(); it!=macros.end(); ++it ) { MacroCommand* macro = new MacroCommand((*it)->GetGroupName()); macro->setScriptName ( (*it)->GetASCII( "Script" ).c_str() ); macro->setMenuText ( (*it)->GetASCII( "Menu" ).c_str() ); macro->setToolTipText ( (*it)->GetASCII( "Tooltip" ).c_str() ); macro->setWhatsThis ( (*it)->GetASCII( "WhatsThis" ).c_str() ); macro->setStatusTip ( (*it)->GetASCII( "Statustip" ).c_str() ); if ((*it)->GetASCII("Pixmap", "nix") != "nix") macro->setPixmap ( (*it)->GetASCII( "Pixmap" ).c_str() ); macro->setAccel ( (*it)->GetASCII( "Accel",0 ).c_str() ); Application::Instance->commandManager().addCommand( macro ); } } }
void DlgSettingsFemImp::saveSettings() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Fem"); hGrp->SetInt("AnalysisType", cb_analysis_type->currentIndex()); fc_analysis_working_directory->onSave(); cb_int_editor->onSave(); fc_ext_editor->onSave(); fc_ccx_binary->onSave(); fc_z88_binary->onSave(); cb_analysis_type->onSave(); sb_eigenmode_number->onSave(); dsb_eigenmode_high_limit->onSave(); dsb_eigenmode_low_limit->onSave(); cb_use_built_in_materials->onSave(); cb_use_mat_from_config_dir->onSave(); cb_use_mat_from_custom_dir->onSave(); fc_custom_mat_dir->onSave(); cb_restore_result_dialog->onSave(); }
/** Resets the accelerator of the selected command to the default. */ void DlgCustomKeyboardImp::on_buttonReset_clicked() { QTreeWidgetItem* item = commandTreeWidget->currentItem(); if (!item) return; QVariant data = item->data(1, Qt::UserRole); QByteArray name = data.toByteArray(); // command name CommandManager & cCmdMgr = Application::Instance->commandManager(); Command* cmd = cCmdMgr.getCommandByName(name.constData()); if (cmd && cmd->getAction()) { cmd->getAction()->setShortcut(QString::fromLatin1(cmd->getAccel())); QString txt = cmd->getAction()->shortcut().toString(QKeySequence::NativeText); accelLineEditShortcut->setText((txt.isEmpty() ? tr("none") : txt)); ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); hGrp->RemoveASCII(name.constData()); } buttonReset->setEnabled( false ); }
void DlgSettingsFemImp::loadSettings() { fc_ccx_working_directory->onRestore(); cb_int_editor->onRestore(); fc_ext_editor->onRestore(); fc_ccx_binary->onRestore(); cb_analysis_type->onRestore(); sb_eigenmode_number->onRestore(); dsb_eigenmode_high_limit->onRestore(); dsb_eigenmode_low_limit->onRestore(); cb_use_built_in_materials->onRestore(); cb_use_mat_from_config_dir->onRestore(); cb_use_mat_from_custom_dir->onRestore(); fc_custom_mat_dir->onRestore(); cb_restore_result_dialog->onRestore(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Fem"); int index = hGrp->GetInt("AnalysisType", 0); if (index > -1) cb_analysis_type->setCurrentIndex(index); }
ViewProviderDatum::ViewProviderDatum() { pShapeSep = new SoSeparator(); pShapeSep->ref(); pPickStyle = new SoPickStyle(); pPickStyle->ref(); DisplayMode.setStatus(App::Property::Hidden, true); // set default color for datums (golden yellow with 60% transparency) ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ( "User parameter:BaseApp/Preferences/Mod/PartDesign"); unsigned long shcol = hGrp->GetUnsigned ( "DefaultDatumColor", 0xFFD70099 ); App::Color col ( (uint32_t) shcol ); ShapeColor.setValue ( col ); Transparency.setValue (col.a * 100); oldWb = ""; oldTip = NULL; }
CombiView::CombiView(Gui::Document* pcDocument, QWidget *parent) : DockWindow(pcDocument,parent), oldTabIndex(0) { setWindowTitle(tr("CombiView")); QGridLayout* pLayout = new QGridLayout(this); pLayout->setSpacing( 0 ); pLayout->setMargin ( 0 ); // tabs to switch between Tree/Properties and TaskPanel tabs = new QTabWidget (); tabs->setObjectName(QString::fromUtf8("combiTab")); tabs->setTabPosition(QTabWidget::North); pLayout->addWidget( tabs, 0, 0 ); // splitter between tree and property view QSplitter *splitter = new QSplitter(); splitter->setOrientation(Qt::Vertical); // tree widget tree = new TreeWidget(this); //tree->setRootIsDecorated(false); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/TreeView"); tree->setIndentation(hGrp->GetInt("Indentation", tree->indentation())); splitter->addWidget(tree); // property view prop = new PropertyView(this); splitter->addWidget(prop); tabs->addTab(splitter,trUtf8("Model")); // task panel taskPanel = new Gui::TaskView::TaskView(this); tabs->addTab(taskPanel, trUtf8("Tasks")); // task panel //projectView = new Gui::ProjectWidget(this); //tabs->addTab(projectView, trUtf8("Project")); }
void Workbench::setupCustomShortcuts() const { // Assigns user defined accelerators ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter(); if ( hGrp->HasGroup("Shortcut") ) { hGrp = hGrp->GetGroup("Shortcut"); // Get all user defined shortcuts const CommandManager& cCmdMgr = Application::Instance->commandManager(); std::vector<std::pair<std::string,std::string> > items = hGrp->GetASCIIMap(); for ( std::vector<std::pair<std::string,std::string> >::iterator it = items.begin(); it != items.end(); ++it ) { Command* cmd = cCmdMgr.getCommandByName(it->first.c_str()); if (cmd && cmd->getAction()) { // may be UTF-8 encoded QString str = QString::fromUtf8(it->second.c_str()); QKeySequence shortcut = str; cmd->getAction()->setShortcut(shortcut); } } } }
void TaskSketcherSolverAdvanced::updateDefaultMethodParameters(void) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/SolverAdvanced"); switch(ui->comboBoxDefaultSolver->currentIndex()) { case 0: // BFGS ui->labelSolverParam1->setText(QString::fromLatin1("")); ui->labelSolverParam2->setText(QString::fromLatin1("")); ui->labelSolverParam3->setText(QString::fromLatin1("")); ui->lineEditSolverParam1->clear(); ui->lineEditSolverParam2->clear(); ui->lineEditSolverParam3->clear(); ui->lineEditSolverParam1->setDisabled(true); ui->lineEditSolverParam2->setDisabled(true); ui->lineEditSolverParam3->setDisabled(true); break; case 1: // LM { ui->labelSolverParam1->setText(QString::fromLatin1("Eps")); ui->labelSolverParam2->setText(QString::fromLatin1("Eps1")); ui->labelSolverParam3->setText(QString::fromLatin1("Tau")); ui->lineEditSolverParam1->setEnabled(true); ui->lineEditSolverParam2->setEnabled(true); ui->lineEditSolverParam3->setEnabled(true); double eps = ::atof(hGrp->GetASCII("LM_eps",QString::number(LM_EPS).toUtf8()).c_str()); double eps1 = ::atof(hGrp->GetASCII("LM_eps1",QString::number(LM_EPS1).toUtf8()).c_str()); double tau = ::atof(hGrp->GetASCII("LM_tau",QString::number(LM_TAU).toUtf8()).c_str()); ui->lineEditSolverParam1->setText(QString::number(eps).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); ui->lineEditSolverParam2->setText(QString::number(eps1).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); ui->lineEditSolverParam3->setText(QString::number(tau).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); sketchView->getSketchObject()->getSolvedSketch().setLM_eps(eps); sketchView->getSketchObject()->getSolvedSketch().setLM_eps1(eps1); sketchView->getSketchObject()->getSolvedSketch().setLM_tau(tau); break; } case 2: // DogLeg { ui->labelSolverParam1->setText(QString::fromLatin1("Tolg")); ui->labelSolverParam2->setText(QString::fromLatin1("Tolx")); ui->labelSolverParam3->setText(QString::fromLatin1("Tolf")); ui->lineEditSolverParam1->setEnabled(true); ui->lineEditSolverParam2->setEnabled(true); ui->lineEditSolverParam3->setEnabled(true); double tolg = ::atof(hGrp->GetASCII("DL_tolg",QString::number(DL_TOLG).toUtf8()).c_str()); double tolx = ::atof(hGrp->GetASCII("DL_tolx",QString::number(DL_TOLX).toUtf8()).c_str()); double tolf = ::atof(hGrp->GetASCII("DL_tolf",QString::number(DL_TOLF).toUtf8()).c_str()); ui->lineEditSolverParam1->setText(QString::number(tolg).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); ui->lineEditSolverParam2->setText(QString::number(tolx).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); ui->lineEditSolverParam3->setText(QString::number(tolf).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper())); sketchView->getSketchObject()->getSolvedSketch().setDL_tolg(tolg); sketchView->getSketchObject()->getSolvedSketch().setDL_tolf(tolf); sketchView->getSketchObject()->getSolvedSketch().setDL_tolx(tolx); break; } } }
void SketcherSettings::saveSettings() { // Sketcher ui->SketchEdgeColor->onSave(); ui->SketchVertexColor->onSave(); ui->EditedEdgeColor->onSave(); ui->EditedVertexColor->onSave(); ui->ConstructionColor->onSave(); ui->ExternalColor->onSave(); ui->FullyConstrainedColor->onSave(); ui->ConstrainedColor->onSave(); ui->NonDrivingConstraintColor->onSave(); ui->DatumColor->onSave(); ui->SketcherDatumWidth->onSave(); ui->DefaultSketcherVertexWidth->onSave(); ui->DefaultSketcherLineWidth->onSave(); ui->CursorTextColor->onSave(); // Sketch editing ui->EditSketcherFontSize->onSave(); ui->dialogOnDistanceConstraint->onSave(); ui->continueMode->onSave(); ui->checkBoxAdvancedSolverTaskBox->onSave(); form->saveSettings(); ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); int markerSize = ui->EditSketcherMarkerSize->itemData(ui->EditSketcherMarkerSize->currentIndex()).toInt(); hViewGrp->SetInt("EditSketcherMarkerSize", markerSize); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); QVariant data = ui->comboBox->itemData(ui->comboBox->currentIndex()); int pattern = data.toInt(); hGrp->SetInt("GridLinePattern", pattern); }
bool ViewProviderPartExt::loadParameter() { bool changed = false; ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Part"); float deviation = hGrp->GetFloat("MeshDeviation",0.2); bool novertexnormals = hGrp->GetBool("NoPerVertexNormals",false); bool qualitynormals = hGrp->GetBool("QualityNormals",false); if (Deviation.getValue() != deviation) { Deviation.setValue(deviation); changed = true; } if (this->noPerVertexNormals != novertexnormals) { this->noPerVertexNormals = novertexnormals; changed = true; } if (this->qualityNormals != qualitynormals) { this->qualityNormals = qualitynormals; changed = true; } return changed; }
void MacroManager::run(MacroType eType, const char *sName) { Q_UNUSED(eType); try { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("OutputWindow"); PyObject* pyout = hGrp->GetBool("RedirectPythonOutput",true) ? new OutputStdout : 0; PyObject* pyerr = hGrp->GetBool("RedirectPythonErrors",true) ? new OutputStderr : 0; PythonRedirector std_out("stdout",pyout); PythonRedirector std_err("stderr",pyerr); //The given path name is expected to be Utf-8 Base::Interpreter().runFile(sName, this->localEnv); } catch (const Base::SystemExitException&) { throw; } catch (const Base::PyException& e) { e.ReportException(); } catch (const Base::Exception& e) { qWarning("%s",e.what()); } }
void ImpExpDxfWrite::setOptions(void) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(getOptionSource().c_str()); optionMaxLength = hGrp->GetFloat("maxsegmentlength",5.0); optionExpPoints = hGrp->GetBool("ExportPoints",false); m_version = hGrp->GetInt("DxfVersionOut",14); optionPolyLine = hGrp->GetBool("DiscretizeEllipses",false); m_polyOverride = hGrp->GetBool("DiscretizeEllipses",false); setDataDir(App::Application::getResourceDir() + "Mod/Import/DxfPlate/"); }
void DlgCustomToolbars::exportCustomToolbars(const QByteArray& workbench) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench"); const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar"); hGrp = hGrp->GetGroup(workbench.constData())->GetGroup(subgroup); hGrp->Clear(); CommandManager& rMgr = Application::Instance->commandManager(); for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) { QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i); QString groupName = QString::fromLatin1("Custom_%1").arg(i+1); QByteArray toolbarName = toplevel->text(0).toUtf8(); ParameterGrp::handle hToolGrp = hGrp->GetGroup(groupName.toLatin1()); hToolGrp->SetASCII("Name", toolbarName.constData()); hToolGrp->SetBool("Active", toplevel->checkState(0) == Qt::Checked); // since we store the separators to the user parameters as (key, pair) we must // make sure to use a unique key because otherwise we cannot store more than // one. int suffixSeparator = 1; for (int j=0; j<toplevel->childCount(); j++) { QTreeWidgetItem* child = toplevel->child(j); QByteArray commandName = child->data(0, Qt::UserRole).toByteArray(); if (commandName == "Separator") { QByteArray key = commandName + QByteArray::number(suffixSeparator); suffixSeparator++; hToolGrp->SetASCII(key, commandName); } else { Command* pCmd = rMgr.getCommandByName(commandName); if (pCmd) { hToolGrp->SetASCII(pCmd->getName(), pCmd->getAppModuleName()); } } } } }
void MacroCommand::save() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Macro")->GetGroup("Macros"); hGrp->Clear(); std::vector<Command*> macros = Application::Instance->commandManager().getGroupCommands("Macros"); if ( macros.size() > 0 ) { for (std::vector<Command*>::iterator it = macros.begin(); it!=macros.end(); ++it ) { MacroCommand* macro = (MacroCommand*)(*it); ParameterGrp::handle hMacro = hGrp->GetGroup(macro->getName()); hMacro->SetASCII( "Script", macro->getScriptName () ); hMacro->SetASCII( "Menu", macro->getMenuText () ); hMacro->SetASCII( "Tooltip", macro->getToolTipText() ); hMacro->SetASCII( "WhatsThis", macro->getWhatsThis () ); hMacro->SetASCII( "Statustip", macro->getStatusTip () ); hMacro->SetASCII( "Pixmap", macro->getPixmap () ); hMacro->SetASCII( "Accel", macro->getAccel () ); } } }
void DlgCustomToolbars::importCustomToolbars(const QByteArray& name) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench"); const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar"); if (!hGrp->HasGroup(name.constData())) return; hGrp = hGrp->GetGroup(name.constData()); if (!hGrp->HasGroup(subgroup)) return; hGrp = hGrp->GetGroup(subgroup); std::string separator = "Separator"; std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups(); CommandManager& rMgr = Application::Instance->commandManager(); for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) { // create a toplevel item QTreeWidgetItem* toplevel = new QTreeWidgetItem(toolbarTreeWidget); bool active = (*it)->GetBool("Active", true); toplevel->setCheckState(0, (active ? Qt::Checked : Qt::Unchecked)); // get the elements of the subgroups std::vector<std::pair<std::string,std::string> > items = (*it)->GetASCIIMap(); for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) { // since we have stored the separators to the user parameters as (key, pair) we had to // make sure to use a unique key because otherwise we cannot store more than // one. if (it2->first.substr(0, separator.size()) == separator) { QTreeWidgetItem* item = new QTreeWidgetItem(toplevel); item->setText(0, tr("<Separator>")); item->setData(0, Qt::UserRole, QByteArray("Separator")); item->setSizeHint(0, QSize(32, 32)); } else if (it2->first == "Name") { QString toolbarName = QString::fromUtf8(it2->second.c_str()); toplevel->setText(0, toolbarName); } else { Command* pCmd = rMgr.getCommandByName(it2->first.c_str()); if (pCmd) { // command name QTreeWidgetItem* item = new QTreeWidgetItem(toplevel); item->setText(0, qApp->translate(pCmd->className(), pCmd->getMenuText())); item->setData(0, Qt::UserRole, QByteArray(it2->first.c_str())); if (pCmd->getPixmap()) item->setIcon(0, BitmapFactory().iconFromTheme(pCmd->getPixmap())); item->setSizeHint(0, QSize(32, 32)); } } } } }
void DlgSettings3DViewImp::loadSettings() { checkBoxZoomAtCursor->onRestore(); checkBoxInvertZoom->onRestore(); spinBoxZoomStep->onRestore(); checkBoxDragAtCursor->onRestore(); CheckBox_CornerCoordSystem->onRestore(); CheckBox_ShowFPS->onRestore(); CheckBox_useVBO->onRestore(); CheckBox_NaviCube->onRestore(); CheckBox_UseAutoRotation->onRestore(); FloatSpinBox_EyeDistance->onRestore(); checkBoxBacklight->onRestore(); backlightColor->onRestore(); sliderIntensity->onRestore(); radioPerspective->onRestore(); radioOrthographic->onRestore(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); std::string model = hGrp->GetASCII("NavigationStyle",CADNavigationStyle::getClassTypeId().getName()); int index = comboNavigationStyle->findData(QByteArray(model.c_str())); if (index > -1) comboNavigationStyle->setCurrentIndex(index); index = hGrp->GetInt("OrbitStyle", int(NavigationStyle::Trackball)); index = Base::clamp(index, 0, comboOrbitStyle->count()-1); comboOrbitStyle->setCurrentIndex(index); index = hGrp->GetInt("AntiAliasing", int(Gui::View3DInventorViewer::None)); index = Base::clamp(index, 0, comboAliasing->count()-1); comboAliasing->setCurrentIndex(index); // connect after setting current item of the combo box connect(comboAliasing, SIGNAL(currentIndexChanged(int)), this, SLOT(onAliasingChanged(int))); index = hGrp->GetInt("CornerNaviCube", 1); naviCubeCorner->setCurrentIndex(index); int const current = hGrp->GetInt("MarkerSize", 9L); this->boxMarkerSize->addItem(tr("5px"), QVariant(5)); this->boxMarkerSize->addItem(tr("7px"), QVariant(7)); this->boxMarkerSize->addItem(tr("9px"), QVariant(9)); this->boxMarkerSize->addItem(tr("11px"), QVariant(11)); this->boxMarkerSize->addItem(tr("13px"), QVariant(13)); this->boxMarkerSize->addItem(tr("15px"), QVariant(15)); index = this->boxMarkerSize->findData(QVariant(current)); if (index < 0) index = 2; this->boxMarkerSize->setCurrentIndex(index); }
void DlgSettings3DViewImp::saveSettings() { // must be done as very first because we create a new instance of NavigatorStyle // where we set some attributes afterwards ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); QVariant data = comboNavigationStyle->itemData(comboNavigationStyle->currentIndex(), Qt::UserRole); hGrp->SetASCII("NavigationStyle", (const char*)data.toByteArray()); int index = comboOrbitStyle->currentIndex(); hGrp->SetInt("OrbitStyle", index); index = this->comboAliasing->currentIndex(); hGrp->SetInt("AntiAliasing", index); index = this->naviCubeCorner->currentIndex(); hGrp->SetInt("CornerNaviCube", index); QVariant const &vBoxMarkerSize = this->boxMarkerSize->itemData(this->boxMarkerSize->currentIndex()); hGrp->SetInt("MarkerSize", vBoxMarkerSize.toInt()); checkBoxZoomAtCursor->onSave(); checkBoxInvertZoom->onSave(); spinBoxZoomStep->onSave(); checkBoxDragAtCursor->onSave(); CheckBox_CornerCoordSystem->onSave(); CheckBox_ShowFPS->onSave(); CheckBox_useVBO->onSave(); CheckBox_NaviCube->onSave(); CheckBox_UseAutoRotation->onSave(); FloatSpinBox_EyeDistance->onSave(); checkBoxBacklight->onSave(); backlightColor->onSave(); sliderIntensity->onSave(); radioPerspective->onSave(); radioOrthographic->onSave(); }
int main( int argc, char ** argv ) { #if defined (FC_OS_LINUX) || defined(FC_OS_BSD) // Make sure to setup the Qt locale system before setting LANG and LC_ALL to C. // which is needed to use the system locale settings. (void)QLocale::system(); // http://www.freecadweb.org/tracker/view.php?id=399 // Because of setting LANG=C the Qt automagic to use the correct encoding // for file names is broken. This is a workaround to force the use of UTF-8 encoding QFile::setEncodingFunction(myEncoderFunc); QFile::setDecodingFunction(myDecoderFunc); // Make sure that we use '.' as decimal point. See also // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846 putenv("LC_NUMERIC=C"); putenv("PYTHONPATH="); #elif defined(FC_OS_MACOSX) (void)QLocale::system(); putenv("LC_NUMERIC=C"); putenv("PYTHONPATH="); #else setlocale(LC_NUMERIC, "C"); _putenv("PYTHONPATH="); #endif #if defined (FC_OS_WIN32) int argc_ = argc; QVector<QByteArray> data; QVector<char *> argv_; // get the command line arguments as unicode string { QCoreApplication app(argc, argv); QStringList args = app.arguments(); for (QStringList::iterator it = args.begin(); it != args.end(); ++it) { data.push_back(it->toUtf8()); argv_.push_back(data.back().data()); } argv_.push_back(0); // 0-terminated string } #endif // Name and Version of the Application App::Application::Config()["ExeName"] = "FreeCAD"; App::Application::Config()["ExeVendor"] = "FreeCAD"; App::Application::Config()["AppDataSkipVendor"] = "true"; App::Application::Config()["MaintainerUrl"] = "http://www.freecadweb.org/wiki/index.php?title=Main_Page"; // set the banner (for logging and console) App::Application::Config()["CopyrightInfo"] = sBanner; App::Application::Config()["AppIcon"] = "freecad"; App::Application::Config()["SplashScreen"] = "freecadsplash"; App::Application::Config()["StartWorkbench"] = "StartWorkbench"; //App::Application::Config()["HiddenDockWindow"] = "Property editor"; App::Application::Config()["SplashAlignment" ] = "Bottom|Left"; App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey try { // Init phase =========================================================== // sets the default run mode for FC, starts with gui if not overridden in InitConfig... App::Application::Config()["RunMode"] = "Gui"; // Inits the Application #if defined (FC_OS_WIN32) App::Application::init(argc_, argv_.data()); #else App::Application::init(argc, argv); #endif #if defined(_MSC_VER) // create a dump file when the application crashes std::string dmpfile = App::Application::getUserAppDataDir(); dmpfile += "crash.dmp"; InitMiniDumpWriter(dmpfile); #endif std::map<std::string, std::string>::iterator it = App::Application::Config().find("NavigationStyle"); if (it != App::Application::Config().end()) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); // if not already defined do it now (for the very first start) std::string style = hGrp->GetASCII("NavigationStyle", it->second.c_str()); hGrp->SetASCII("NavigationStyle", style.c_str()); } Gui::Application::initApplication(); // Only if 'RunMode' is set to 'Gui' do the replacement if (App::Application::Config()["RunMode"] == "Gui") Base::Interpreter().replaceStdOutput(); } catch (const Base::UnknownProgramOption& e) { QApplication app(argc,argv); QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); QString msg = QString::fromAscii(e.what()); QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>"); QMessageBox::critical(0, appName, s); exit(1); } catch (const Base::ProgramInformation& e) { QApplication app(argc,argv); QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); QString msg = QString::fromAscii(e.what()); QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>"); QMessageBox::information(0, appName, s); exit(0); } catch (const Base::Exception& e) { // Popup an own dialog box instead of that one of Windows QApplication app(argc,argv); QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); QString msg; msg = QObject::tr("While initializing %1 the following exception occurred: '%2'\n\n" "Python is searching for its files in the following directories:\n%3\n\n" "Python version information:\n%4\n") .arg(appName).arg(QString::fromUtf8(e.what())) .arg(QString::fromUtf8(Py_GetPath())).arg(QString::fromAscii(Py_GetVersion())); const char* pythonhome = getenv("PYTHONHOME"); if (pythonhome) { msg += QObject::tr("\nThe environment variable PYTHONHOME is set to '%1'.") .arg(QString::fromUtf8(pythonhome)); msg += QObject::tr("\nSetting this environment variable might cause Python to fail. " "Please contact your administrator to unset it on your system.\n\n"); } else { msg += QObject::tr("\nPlease contact the application's support team for more information.\n\n"); } QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg); exit(100); } catch (...) { // Popup an own dialog box instead of that one of Windows QApplication app(argc,argv); QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); QString msg = QObject::tr("Unknown runtime error occurred while initializing %1.\n\n" "Please contact the application's support team for more information.\n\n").arg(appName); QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg); exit(101); } // Run phase =========================================================== Base::RedirectStdOutput stdcout; Base::RedirectStdLog stdclog; Base::RedirectStdError stdcerr; std::streambuf* oldcout = std::cout.rdbuf(&stdcout); std::streambuf* oldclog = std::clog.rdbuf(&stdclog); std::streambuf* oldcerr = std::cerr.rdbuf(&stdcerr); try { if (App::Application::Config()["RunMode"] == "Gui") Gui::Application::runApplication(); else App::Application::runApplication(); } catch (const Base::SystemExitException&) { exit(0); } catch (const Base::Exception& e) { Base::Console().Error("%s\n", e.what()); } catch (...) { Base::Console().Error("Application unexpectedly terminated\n"); } std::cout.rdbuf(oldcout); std::clog.rdbuf(oldclog); std::cerr.rdbuf(oldcerr); // Destruction phase =========================================================== Base::Console().Log("%s terminating...\n",App::Application::Config()["ExeName"].c_str()); // cleans up App::Application::destruct(); Base::Console().Log("%s completely terminated\n",App::Application::Config()["ExeName"].c_str()); return 0; }
int main( int argc, char ** argv ) { #if defined (FC_OS_LINUX) || defined(FC_OS_BSD) // Make sure to setup the Qt locale system before setting LANG and LC_ALL to C. // which is needed to use the system locale settings. (void)QLocale::system(); #if QT_VERSION < 0x050000 // http://www.freecadweb.org/tracker/view.php?id=399 // Because of setting LANG=C the Qt automagic to use the correct encoding // for file names is broken. This is a workaround to force the use of UTF-8 encoding QFile::setEncodingFunction(myEncoderFunc); QFile::setDecodingFunction(myDecoderFunc); #endif // See https://forum.freecadweb.org/viewtopic.php?f=18&t=20600 // See Gui::Application::runApplication() putenv("LC_NUMERIC=C"); putenv("PYTHONPATH="); #elif defined(FC_OS_MACOSX) (void)QLocale::system(); putenv("PYTHONPATH="); #else _putenv("PYTHONPATH="); // https://forum.freecadweb.org/viewtopic.php?f=4&t=18288 // https://forum.freecadweb.org/viewtopic.php?f=3&t=20515 const char* fc_py_home = getenv("FC_PYTHONHOME"); if (fc_py_home) _putenv_s("PYTHONHOME", fc_py_home); else _putenv("PYTHONHOME="); #endif #if defined (FC_OS_WIN32) int argc_ = argc; QVector<QByteArray> data; QVector<char *> argv_; // get the command line arguments as unicode string { QCoreApplication app(argc, argv); QStringList args = app.arguments(); for (QStringList::iterator it = args.begin(); it != args.end(); ++it) { data.push_back(it->toUtf8()); argv_.push_back(data.back().data()); } argv_.push_back(0); // 0-terminated string } #endif #if PY_MAJOR_VERSION >= 3 #if defined(_MSC_VER) && _MSC_VER <= 1800 // See InterpreterSingleton::init Redirection out(stdout), err(stderr), inp(stdin); #endif #endif // PY_MAJOR_VERSION // Name and Version of the Application App::Application::Config()["ExeName"] = "FreeCAD"; App::Application::Config()["ExeVendor"] = "FreeCAD"; App::Application::Config()["AppDataSkipVendor"] = "true"; App::Application::Config()["MaintainerUrl"] = "http://www.freecadweb.org/wiki/Main_Page"; // set the banner (for logging and console) App::Application::Config()["CopyrightInfo"] = sBanner; App::Application::Config()["AppIcon"] = "freecad"; App::Application::Config()["SplashScreen"] = "freecadsplash"; App::Application::Config()["StartWorkbench"] = "StartWorkbench"; //App::Application::Config()["HiddenDockWindow"] = "Property editor"; App::Application::Config()["SplashAlignment" ] = "Bottom|Left"; App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey try { // Init phase =========================================================== // sets the default run mode for FC, starts with gui if not overridden in InitConfig... App::Application::Config()["RunMode"] = "Gui"; App::Application::Config()["Console"] = "0"; // Inits the Application #if defined (FC_OS_WIN32) App::Application::init(argc_, argv_.data()); #else App::Application::init(argc, argv); #endif #if defined(_MSC_VER) // create a dump file when the application crashes std::string dmpfile = App::Application::getUserAppDataDir(); dmpfile += "crash.dmp"; InitMiniDumpWriter(dmpfile); #endif std::map<std::string, std::string>::iterator it = App::Application::Config().find("NavigationStyle"); if (it != App::Application::Config().end()) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); // if not already defined do it now (for the very first start) std::string style = hGrp->GetASCII("NavigationStyle", it->second.c_str()); hGrp->SetASCII("NavigationStyle", style.c_str()); } Gui::Application::initApplication(); // Only if 'RunMode' is set to 'Gui' do the replacement if (App::Application::Config()["RunMode"] == "Gui") Base::Interpreter().replaceStdOutput(); } catch (const Base::UnknownProgramOption& e) { QApplication app(argc,argv); QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str()); QString msg = QString::fromLatin1(e.what()); QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>"); QMessageBox::critical(0, appName, s); exit(1); } catch (const Base::ProgramInformation& e) { QApplication app(argc,argv); QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str()); QString msg = QString::fromUtf8(e.what()); QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>"); QMessageBox msgBox; msgBox.setIcon(QMessageBox::Information); msgBox.setWindowTitle(appName); msgBox.setDetailedText(msg); msgBox.setText(s); msgBox.exec(); exit(0); } catch (const Base::Exception& e) { // Popup an own dialog box instead of that one of Windows QApplication app(argc,argv); QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str()); QString msg; msg = QObject::tr("While initializing %1 the following exception occurred: '%2'\n\n" "Python is searching for its files in the following directories:\n%3\n\n" "Python version information:\n%4\n") .arg(appName).arg(QString::fromUtf8(e.what())) #if PY_MAJOR_VERSION >= 3 #if PY_MINOR_VERSION >= 5 .arg(QString::fromUtf8(Py_EncodeLocale(Py_GetPath(),NULL))).arg(QString::fromLatin1(Py_GetVersion())); #else .arg(QString::fromUtf8(_Py_wchar2char(Py_GetPath(),NULL))).arg(QString::fromLatin1(Py_GetVersion())); #endif #else .arg(QString::fromUtf8(Py_GetPath())).arg(QString::fromLatin1(Py_GetVersion()));
DraftDxfRead::DraftDxfRead(std::string filepath, App::Document *pcDoc) : CDxfRead(filepath.c_str()) { document = pcDoc; ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Draft"); optionGroupLayers = hGrp->GetBool("groupLayers",false); }
void Gui::GUIApplicationNativeEventAware::importSettings() { ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Spaceball")->GetGroup("Motion"); // here I import settings from a dialog. For now they are set as is bool dominant = group->GetBool("Dominant"); // Is dominant checked bool flipXY = group->GetBool("FlipYZ");; // Is Flip X/Y checked float generalSensitivity = convertPrefToSensitivity(group->GetInt("GlobalSensitivity")); // array that has stored info about "Enabled" checkboxes of all axes bool enabled[6]; enabled[0] = group->GetBool("Translations", true) && group->GetBool("PanLREnable", true); enabled[1] = group->GetBool("Translations", true) && group->GetBool("PanUDEnable", true); enabled[2] = group->GetBool("Translations", true) && group->GetBool("ZoomEnable", true); enabled[3] = group->GetBool("Rotations", true) && group->GetBool("TiltEnable", true); enabled[4] = group->GetBool("Rotations", true) && group->GetBool("RollEnable", true); enabled[5] = group->GetBool("Rotations", true) && group->GetBool("SpinEnable", true); // array that has stored info about "Reversed" checkboxes of all axes bool reversed[6]; reversed[0] = group->GetBool("PanLRReverse"); reversed[1] = group->GetBool("PanUDReverse"); reversed[2] = group->GetBool("ZoomReverse"); reversed[3] = group->GetBool("TiltReverse"); reversed[4] = group->GetBool("RollReverse"); reversed[5] = group->GetBool("SpinReverse"); // array that has stored info about sliders - on each slider you need to use method DlgSpaceballSettings::GetValuefromSlider // which will convert <-50, 50> linear integers from slider to <0.1, 10> exponential floating values float sensitivity[6]; sensitivity[0] = convertPrefToSensitivity(group->GetInt("PanLRSensitivity")); sensitivity[1] = convertPrefToSensitivity(group->GetInt("PanUDSensitivity")); sensitivity[2] = convertPrefToSensitivity(group->GetInt("ZoomSensitivity")); sensitivity[3] = convertPrefToSensitivity(group->GetInt("TiltSensitivity")); sensitivity[4] = convertPrefToSensitivity(group->GetInt("RollSensitivity")); sensitivity[5] = convertPrefToSensitivity(group->GetInt("SpinSensitivity")); if (group->GetBool("Calibrate")) { group->SetInt("CalibrationX",motionDataArray[0]); group->SetInt("CalibrationY",motionDataArray[1]); group->SetInt("CalibrationZ",motionDataArray[2]); group->SetInt("CalibrationXr",motionDataArray[3]); group->SetInt("CalibrationYr",motionDataArray[4]); group->SetInt("CalibrationZr",motionDataArray[5]); group->RemoveBool("Calibrate"); return; } else { motionDataArray[0] = motionDataArray[0] - group->GetInt("CalibrationX"); motionDataArray[1] = motionDataArray[1] - group->GetInt("CalibrationY"); motionDataArray[2] = motionDataArray[2] - group->GetInt("CalibrationZ"); motionDataArray[3] = motionDataArray[3] - group->GetInt("CalibrationXr"); motionDataArray[4] = motionDataArray[4] - group->GetInt("CalibrationYr"); motionDataArray[5] = motionDataArray[5] - group->GetInt("CalibrationZr"); } int i; if (flipXY) { bool tempBool; float tempFloat; tempBool = enabled[1]; enabled[1] = enabled[2]; enabled[2] = tempBool; tempBool = enabled[4]; enabled[4] = enabled[5]; enabled[5] = tempBool; tempBool = reversed[1]; reversed[1] = reversed[2]; reversed[2] = tempBool; tempBool = reversed[4]; reversed[4] = reversed[5]; reversed[5] = tempBool; tempFloat = sensitivity[1]; sensitivity[1] = sensitivity[2]; sensitivity[2] = tempFloat; tempFloat = sensitivity[4]; sensitivity[4] = sensitivity[5]; sensitivity[5] = tempFloat; i = motionDataArray[1]; motionDataArray[1] = motionDataArray[2]; motionDataArray[2] = - i; i = motionDataArray[4]; motionDataArray[4] = motionDataArray[5]; motionDataArray[5] = - i; } if (dominant) { // if dominant is checked int max = 0; bool flag = false; for (i = 0; i < 6; ++i) { if (abs(motionDataArray[i]) > abs(max)) max = motionDataArray[i]; } for (i = 0; i < 6; ++i) { if ((motionDataArray[i] != max) || (flag)) { motionDataArray[i] = 0; } else if (motionDataArray[i] == max) { flag = true; } } } for (i = 0; i < 6; ++i) { if (motionDataArray[i] != 0) { if (enabled[i] == false) motionDataArray[i] = 0; else { if (reversed[i] == true) motionDataArray[i] = - motionDataArray[i]; motionDataArray[i] = (int)((float)(motionDataArray[i]) * sensitivity[i] * generalSensitivity); } } } }
void TaskSketcherSolverAdvanced::on_pushButtonDefaults_clicked(bool checked/* = false*/) { // Algorithm params for default solvers ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/SolverAdvanced"); hGrp->SetASCII("LM_eps",QString::number(LM_EPS).toUtf8()); hGrp->SetASCII("LM_eps1",QString::number(LM_EPS1).toUtf8()); hGrp->SetASCII("LM_tau",QString::number(LM_TAU).toUtf8()); hGrp->SetASCII("DL_tolg",QString::number(DL_TOLG).toUtf8()); hGrp->SetASCII("DL_tolx",QString::number(DL_TOLX).toUtf8()); hGrp->SetASCII("DL_tolf",QString::number(DL_TOLF).toUtf8()); hGrp->SetASCII("Redundant_LM_eps",QString::number(LM_EPS).toUtf8()); hGrp->SetASCII("Redundant_LM_eps1",QString::number(LM_EPS1).toUtf8()); hGrp->SetASCII("Redundant_LM_tau",QString::number(LM_TAU).toUtf8()); hGrp->SetASCII("Redundant_DL_tolg",QString::number(DL_TOLG).toUtf8()); hGrp->SetASCII("Redundant_DL_tolx",QString::number(DL_TOLX).toUtf8()); hGrp->SetASCII("Redundant_DL_tolf",QString::number(DL_TOLF).toUtf8()); // Set other settings hGrp->SetInt("DefaultSolver",DEFAULT_SOLVER); hGrp->SetInt("DogLegGaussStep",DEFAULT_DOGLEG_GAUSS_STEP); hGrp->SetInt("RedundantDefaultSolver",DEFAULT_RSOLVER); hGrp->SetInt("MaxIter",MAX_ITER); hGrp->SetInt("RedundantSolverMaxIterations",MAX_ITER); hGrp->SetBool("SketchSizeMultiplier",MAX_ITER_MULTIPLIER); hGrp->SetBool("RedundantSketchSizeMultiplier",MAX_ITER_MULTIPLIER); hGrp->SetASCII("Convergence",QString::number(CONVERGENCE).toUtf8()); hGrp->SetASCII("RedundantConvergence",QString::number(CONVERGENCE).toUtf8()); hGrp->SetInt("QRMethod",DEFAULT_QRSOLVER); hGrp->SetASCII("QRPivotThreshold",QString::number(QR_PIVOT_THRESHOLD).toUtf8()); hGrp->SetInt("DebugMode",DEFAULT_SOLVER_DEBUG); ui->comboBoxDefaultSolver->onRestore(); ui->comboBoxDogLegGaussStep->onRestore(); ui->spinBoxMaxIter->onRestore(); ui->checkBoxSketchSizeMultiplier->onRestore(); ui->lineEditConvergence->onRestore(); ui->comboBoxQRMethod->onRestore(); ui->lineEditQRPivotThreshold->onRestore(); ui->comboBoxRedundantDefaultSolver->onRestore(); ui->spinBoxRedundantSolverMaxIterations->onRestore(); ui->checkBoxRedundantSketchSizeMultiplier->onRestore(); ui->lineEditRedundantConvergence->onRestore(); ui->comboBoxDebugMode->onRestore(); updateSketchObject(); }
void StdCmdDownloadOnlineHelp::activated(int iMsg) { if (!wget->isDownloading()) { ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp"); hGrp = hGrp->GetGroup("Preferences")->GetGroup("OnlineHelp"); std::string url = hGrp->GetASCII("DownloadURL", "www.freecadweb.org/wiki/"); std::string prx = hGrp->GetASCII("ProxyText", ""); bool bUseProxy = hGrp->GetBool ("UseProxy", false); bool bAuthor = hGrp->GetBool ("Authorize", false); if (bUseProxy) { QString username = QString::null; QString password = QString::null; if (bAuthor) { QDialog dlg(getMainWindow()); dlg.setModal(true); Ui_DlgAuthorization ui; ui.setupUi(&dlg); if (dlg.exec() == QDialog::Accepted) { username = ui.username->text(); password = ui.password->text(); } } wget->setProxy(QString::fromAscii(prx.c_str()), username, password); } int loop=3; bool canStart = false; // set output directory QString path = QString::fromUtf8(App::GetApplication().GetHomePath()); path += QString::fromAscii("/doc/"); ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp"); path = QString::fromUtf8(hURLGrp->GetASCII( "DownloadLocation", path.toAscii() ).c_str()); while (loop > 0) { loop--; QFileInfo fi( path); if (!fi.exists()) { if (QMessageBox::critical(getMainWindow(), tr("Non-existing directory"), tr("The directory '%1' does not exist.\n\n" "Do you want to specify an existing directory?").arg(fi.filePath()), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) != QMessageBox::Yes) { // exit the command return; } else { path = FileDialog::getExistingDirectory(); if ( path.isEmpty() ) return; } } if (!fi.permission( QFile::WriteUser)) { if (QMessageBox::critical(getMainWindow(), tr("Missing permission"), tr("You don't have write permission to '%1'\n\n" "Do you want to specify another directory?").arg(fi.filePath()), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape) != QMessageBox::Yes) { // exit the command return; } else { path = FileDialog::getExistingDirectory(); if ( path.isEmpty() ) return; } } else { wget->setOutputDirectory( path ); canStart = true; break; } } if (canStart) { bool ok = wget->startDownload(QString::fromAscii(url.c_str())); if ( ok == false ) Base::Console().Error("The tool 'wget' couldn't be found. Please check your installation."); else if ( wget->isDownloading() && _pcAction ) _pcAction->setText(tr("Stop downloading")); } } else // kill the process now { wget->abort(); } }
void ViewProviderInspection::updateData(const App::Property* prop) { // set to the expected size if (prop->getTypeId() == App::PropertyLink::getClassTypeId()) { App::GeoFeature* object = static_cast<const App::PropertyLink*>(prop)->getValue<App::GeoFeature*>(); if (object) { float accuracy=0; Base::Type meshId = Base::Type::fromName("Mesh::Feature"); Base::Type shapeId = Base::Type::fromName("Part::Feature"); Base::Type pointId = Base::Type::fromName("Points::Feature"); Base::Type propId = App::PropertyComplexGeoData::getClassTypeId(); // set the Distance property to the correct size to sync size of material node with number // of vertices/points of the referenced geometry const Data::ComplexGeoData* data = 0; if (object->getTypeId().isDerivedFrom(meshId)) { App::Property* prop = object->getPropertyByName("Mesh"); if (prop && prop->getTypeId().isDerivedFrom(propId)) { data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData(); } } else if (object->getTypeId().isDerivedFrom(shapeId)) { App::Property* prop = object->getPropertyByName("Shape"); if (prop && prop->getTypeId().isDerivedFrom(propId)) { data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Mod/Part"); float deviation = hGrp->GetFloat("MeshDeviation",0.2); Base::BoundBox3d bbox = data->getBoundBox(); accuracy = (float)((bbox.LengthX() + bbox.LengthY() + bbox.LengthZ())/300.0 * deviation); } } else if (object->getTypeId().isDerivedFrom(pointId)) { App::Property* prop = object->getPropertyByName("Points"); if (prop && prop->getTypeId().isDerivedFrom(propId)) { data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData(); } } if (data) { this->pcLinkRoot->removeAllChildren(); std::vector<Base::Vector3d> points; std::vector<Data::ComplexGeoData::Facet> faces; data->getFaces(points, faces, accuracy); this->pcLinkRoot->addChild(this->pcCoords); this->pcCoords->point.setNum(points.size()); SbVec3f* pts = this->pcCoords->point.startEditing(); for (size_t i=0; i < points.size(); i++) { const Base::Vector3d& p = points[i]; pts[i].setValue((float)p.x,(float)p.y,(float)p.z); } this->pcCoords->point.finishEditing(); if (!faces.empty()) { SoIndexedFaceSet* face = new SoIndexedFaceSet(); this->pcLinkRoot->addChild(face); face->coordIndex.setNum(4*faces.size()); int32_t* indices = face->coordIndex.startEditing(); unsigned long j=0; std::vector<Data::ComplexGeoData::Facet>::iterator it; for (it = faces.begin(); it != faces.end(); ++it,j++) { indices[4*j+0] = it->I1; indices[4*j+1] = it->I2; indices[4*j+2] = it->I3; indices[4*j+3] = SO_END_FACE_INDEX; } face->coordIndex.finishEditing(); } else { this->pcLinkRoot->addChild(this->pcPointStyle); this->pcLinkRoot->addChild(new SoPointSet()); } } } } else if (prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { // force an update of the Inventor data nodes if (this->pcObject) { App::Property* link = this->pcObject->getPropertyByName("Actual"); if (link) updateData(link); } setDistances(); } else if (prop->getTypeId() == App::PropertyFloat::getClassTypeId()) { if (strcmp(prop->getName(), "SearchRadius") == 0) { float fSearchRadius = ((App::PropertyFloat*)prop)->getValue(); this->search_radius = fSearchRadius; pcColorBar->setRange( -fSearchRadius, fSearchRadius, 4 ); pcColorBar->Notify(0); } } }
void StdCmdExportGraphviz::activated(int iMsg) { App::Document* doc = App::GetApplication().getActiveDocument(); std::stringstream str; doc->exportGraphviz(str); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Paths"); QProcess proc; QStringList args; args << QLatin1String("-Tpng"); #ifdef FC_OS_LINUX QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz", "/usr/bin").c_str()); #else QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz").c_str()); #endif bool pathChanged = false; #ifdef FC_OS_WIN32 QString exe = QString::fromAscii("\"%1/dot\"").arg(path); #else QString exe = QString::fromAscii("%1/dot").arg(path); #endif proc.setEnvironment(QProcess::systemEnvironment()); do { proc.start(exe, args); if (!proc.waitForStarted()) { int ret = QMessageBox::warning(getMainWindow(), qApp->translate("Std_ExportGraphviz","Graphviz not found"), qApp->translate("Std_ExportGraphviz","Graphviz couldn't be found on your system.\n" "Do you want to specify its installation path if it's already installed?"), QMessageBox::Yes, QMessageBox::No); if (ret == QMessageBox::No) return; path = QFileDialog::getExistingDirectory(Gui::getMainWindow(), qApp->translate("Std_ExportGraphviz","Graphviz installation path")); if (path.isEmpty()) return; pathChanged = true; #ifdef FC_OS_WIN32 exe = QString::fromAscii("\"%1/dot\"").arg(path); #else exe = QString::fromAscii("%1/dot").arg(path); #endif } else { if (pathChanged) hGrp->SetASCII("Graphviz", (const char*)path.toUtf8()); break; } } while(true); proc.write(str.str().c_str(), str.str().size()); proc.closeWriteChannel(); if (!proc.waitForFinished()) return; QPixmap px; if (px.loadFromData(proc.readAll(), "PNG")) { Gui::ImageView* view = new Gui::ImageView(px); view->setWindowTitle(qApp->translate("Std_ExportGraphviz","Dependency graph")); getMainWindow()->addWindow(view); } else { QMessageBox::warning(getMainWindow(), qApp->translate("Std_ExportGraphviz","Graphviz failed"), qApp->translate("Std_ExportGraphviz","Graphviz failed to create an image file")); } }
void TaskCheckGeometryResults::goCheck() { Gui::WaitCursor wc; int selectedCount(0), checkedCount(0), invalidShapes(0); std::vector<Gui::SelectionSingleton::SelObj> selection = Gui::Selection().getSelection(); std::vector<Gui::SelectionSingleton::SelObj>::iterator it; ResultEntry *theRoot = new ResultEntry(); for (it = selection.begin(); it != selection.end(); ++it) { selectedCount++; Part::Feature *feature = dynamic_cast<Part::Feature *>((*it).pObject); if (!feature) continue; currentSeparator = Gui::Application::Instance->activeDocument()->getViewProvider(feature)->getRoot(); if (!currentSeparator) continue; TopoDS_Shape shape = feature->Shape.getValue(); QString baseName; QTextStream baseStream(&baseName); baseStream << (*it).DocName; baseStream << "." << (*it).FeatName; if (strlen((*it).SubName) > 0) { shape = feature->Shape.getShape().getSubShape((*it).SubName); baseStream << "." << (*it).SubName; } if (shape.IsNull()) continue; checkedCount++; checkedMap.Clear(); buildShapeContent(baseName, shape); BRepCheck_Analyzer shapeCheck(shape); if (!shapeCheck.IsValid()) { invalidShapes++; ResultEntry *entry = new ResultEntry(); entry->parent = theRoot; entry->shape = shape; entry->name = baseName; entry->type = shapeEnumToString(shape.ShapeType()); entry->error = QObject::tr("Invalid"); entry->viewProviderRoot = currentSeparator; entry->viewProviderRoot->ref(); goSetupResultBoundingBox(entry); theRoot->children.push_back(entry); recursiveCheck(shapeCheck, shape, entry); continue; //don't run BOPAlgo_ArgumentAnalyzer if BRepCheck_Analyzer finds something. } else { //BOPAlgo_ArgumentAnalyzer can be really slow! //so only run it when the shape seems valid to BRepCheck_Analyzer And //when the option is set. ParameterGrp::handle group = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod")->GetGroup("Part")->GetGroup("CheckGeometry"); bool runSignal = group->GetBool("RunBOPCheck", false); //for now, user has edit the config file to turn it on. //following line ensures that the config file has the setting. group->SetBool("RunBOPCheck", runSignal); if (runSignal) invalidShapes += goBOPSingleCheck(shape, theRoot, baseName); } } model->setResults(theRoot); treeView->expandAll(); treeView->header()->resizeSections(QHeaderView::ResizeToContents); QString aMessage; QTextStream aStream(&aMessage); aStream << checkedCount << " processed out of " << selectedCount << " selected\n"; aStream << invalidShapes << " invalid shapes."; message->setText(aMessage); Gui::Selection().clearSelection(); }
void StdCmdOnlineHelpWebsite::activated(int iMsg) { ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp"); std::string url = hURLGrp->GetASCII("DownloadURL", "http://www.freecadweb.org/wiki/index.php?title=Online_Help_Toc"); OpenURLInBrowser(url.c_str()); }
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(); } }
SoSeparator* ViewProvider2DObject::createGrid(void) { //double dx = 10 * GridSize.getValue(); // carpet size //double dy = 10 * GridSize.getValue(); // float Size = (MaxX-MinX > MaxY-MinY) ? MaxX-MinX : MaxY-MinY; float Step = GridSize.getValue(); //pow(10,floor(log10(Size/5.0))); float MiX, MaX, MiY, MaY; if (TightGrid.getValue()) { MiX = MinX - (MaxX-MinX)*0.2f; MaX = MaxX + (MaxX-MinX)*0.2f; MiY = MinY - (MaxY-MinY)*0.2f; MaY = MaxY + (MaxY-MinY)*0.2f; } else { MiX = -exp(ceil(log(std::abs(MinX)))); MiX = std::min<float>(MiX,(float)-exp(ceil(log(std::abs(0.1f*MaxX))))); MaX = exp(ceil(log(std::abs(MaxX)))); MaX = std::max<float>(MaX,(float)exp(ceil(log(std::abs(0.1f*MinX))))); MiY = -exp(ceil(log(std::abs(MinY)))); MiY = std::min<float>(MiY,(float)-exp(ceil(log(std::abs(0.1f*MaxY))))); MaY = exp(ceil(log(std::abs(MaxY)))); MaY = std::max<float>(MaY,(float)exp(ceil(log(std::abs(0.1f*MinY))))); } //Round the values otherwise grid is not aligned with center MiX = floor(MiX / Step) * Step; MaX = ceil(MaX / Step) * Step; MiY = floor(MiY / Step) * Step; MaY = ceil(MaY / Step) * Step; double zGrid = 0.0; // carpet-grid separation SoGroup *parent = new Gui::SoSkipBoundingGroup(); GridRoot->removeAllChildren(); GridRoot->addChild(parent); SoBaseColor *mycolor; SoVertexProperty *vts; // carpet /* mycolor = new SoBaseColor; mycolor->rgb.setValue(0.2f, 0.7f, 0.7f); parent->addChild(mycolor); vts = new SoVertexProperty; vts->vertex.set1Value(0, -0.5*dx, -1.5*dy, 0.5*zGrid); vts->vertex.set1Value(1, -0.5*dx, -1.5*dy, -0.5*zGrid); vts->vertex.set1Value(2, 0.5*dx, -1.5*dy, 0.5*zGrid); vts->vertex.set1Value(3, 0.5*dx, -1.5*dy, -0.5*zGrid); SoQuadMesh *carpet = new SoQuadMesh; carpet->verticesPerColumn = 2; carpet->verticesPerRow = 2; carpet->vertexProperty = vts; parent->addChild(carpet);*/ // gridlines mycolor = new SoBaseColor; mycolor->rgb.setValue(0.7f, 0.7f ,0.7f); parent->addChild(mycolor); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part"); int pattern = hGrp->GetInt("GridLinePattern", 0x0f0f); SoDrawStyle* DefaultStyle = new SoDrawStyle; DefaultStyle->lineWidth = 1; DefaultStyle->linePattern = pattern; SoMaterial* LightStyle = new SoMaterial; LightStyle->transparency = 0.7f; if (GridStyle.getValue() == 0) parent->addChild(DefaultStyle); else parent->addChild(LightStyle); SoPickStyle* PickStyle = new SoPickStyle; PickStyle->style = SoPickStyle::UNPICKABLE; parent->addChild(PickStyle); SoLineSet *grid = new SoLineSet; vts = new SoVertexProperty; grid->vertexProperty = vts; int vi=0, l=0; // vertical lines float i; for (i=MiX; i<MaX; i+=Step) { /*float h=-0.5*dx + float(i) / gridsize * dx;*/ vts->vertex.set1Value(vi++, i, MiY, zGrid); vts->vertex.set1Value(vi++, i, MaY, zGrid); grid->numVertices.set1Value(l++, 2); } // horizontal lines for (i=MiY; i<MaY; i+=Step) { //float v=-0.5*dy + float(i) / gridsize * dy; vts->vertex.set1Value(vi++, MiX, i, zGrid); vts->vertex.set1Value(vi++, MaX, i, zGrid); grid->numVertices.set1Value(l++, 2); } parent->addChild(vts); parent->addChild(grid); return GridRoot; }