Added per project Unit System feature
This commit is contained in:
@@ -54,6 +54,8 @@
|
||||
#include <Base/Stream.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include <Language/Translator.h>
|
||||
#include <Quarter/Quarter.h>
|
||||
|
||||
@@ -927,6 +929,19 @@ void Application::slotActiveDocument(const App::Document& Doc)
|
||||
Py::Module("FreeCADGui").setAttr(std::string("ActiveDocument"),Py::None());
|
||||
}
|
||||
}
|
||||
|
||||
//Set Unit System.
|
||||
int projectUnitSystemIndex = doc->second->getProjectUnitSystem();
|
||||
int ignore = doc->second->getProjectUnitSystemIgnore();
|
||||
if( projectUnitSystemIndex >= 0 && !ignore ){//is valid
|
||||
Base::UnitsApi::setSchema(static_cast<Base::UnitSystem>(projectUnitSystemIndex));
|
||||
}else{// set up Unit system default
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/Units");
|
||||
Base::UnitsApi::setSchema((Base::UnitSystem)hGrp->GetInt("UserSchema",0));
|
||||
Base::UnitsApi::setDecimals(hGrp->GetInt("Decimals", Base::UnitsApi::getDecimals()));
|
||||
}
|
||||
|
||||
signalActiveDocument(*doc->second);
|
||||
updateActions();
|
||||
}
|
||||
|
||||
@@ -87,14 +87,42 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Project Unit system:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboBox_projectUnitSystem">
|
||||
<property name="toolTip">
|
||||
<string>Unit system used for display metrics stored in project</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="checkBox_projectUnitSystemIgnore">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, Unit System stored in project will be ignored.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ignore</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="fractionalInchLabel">
|
||||
<property name="text">
|
||||
<string>Minimum fractional inch:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="comboBox_FracInch">
|
||||
<property name="toolTip">
|
||||
<string>Minimum fractional inch to be displayed</string>
|
||||
@@ -136,14 +164,14 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="TextLabel1_5">
|
||||
<property name="text">
|
||||
<string>Number format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="Gui::PrefComboBox" name="UseLocaleFormatting">
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>UseLocaleFormatting</cstring>
|
||||
@@ -168,7 +196,7 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="4" column="2">
|
||||
<widget class="Gui::PrefCheckBox" name="SubstituteDecimal">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, numerical keypad decimal separator
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include <Gui/Document.h>
|
||||
|
||||
#include "DlgGeneralImp.h"
|
||||
#include "ui_DlgGeneral.h"
|
||||
#include "Action.h"
|
||||
@@ -50,6 +52,7 @@
|
||||
#include "PreferencePackManager.h"
|
||||
#include "Language/Translator.h"
|
||||
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
namespace fs = boost::filesystem;
|
||||
using namespace Base;
|
||||
@@ -90,6 +93,7 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent )
|
||||
for (int i = 0; i < num; i++) {
|
||||
QString item = qApp->translate("Gui::Dialog::DlgGeneralImp", Base::UnitsApi::getDescription(static_cast<Base::UnitSystem>(i)));
|
||||
ui->comboBox_UnitSystem->addItem(item, i);
|
||||
ui->comboBox_projectUnitSystem->addItem(item, i);
|
||||
}
|
||||
|
||||
// Enable/disable the fractional inch option depending on system
|
||||
@@ -202,7 +206,21 @@ void DlgGeneralImp::saveSettings()
|
||||
|
||||
// Set and save the Unit System
|
||||
viewSystemIndex = ui->comboBox_UnitSystem->currentIndex();
|
||||
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
bool projectUnitSystemIgnore = ui->checkBox_projectUnitSystemIgnore->isChecked();
|
||||
if(activeDoc){
|
||||
activeDoc->setProjectUnitSystemIgnore( projectUnitSystemIgnore );
|
||||
if(!projectUnitSystemIgnore){
|
||||
int projectUnitSystemIndex = ui->comboBox_projectUnitSystem->currentIndex();
|
||||
activeDoc->setProjectUnitSystem( projectUnitSystemIndex );
|
||||
UnitsApi::setSchema(static_cast<UnitSystem>(projectUnitSystemIndex));
|
||||
}else{
|
||||
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
|
||||
}
|
||||
}else{
|
||||
UnitsApi::setSchema(static_cast<UnitSystem>(viewSystemIndex));
|
||||
}
|
||||
//
|
||||
|
||||
ui->SubstituteDecimal->onSave();
|
||||
ui->UseLocaleFormatting->onSave();
|
||||
@@ -268,6 +286,24 @@ void DlgGeneralImp::loadSettings()
|
||||
// handy little equation.
|
||||
cbIndex = std::log2(FracInch) - 1;
|
||||
ui->comboBox_FracInch->setCurrentIndex(cbIndex);
|
||||
|
||||
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(activeDoc){
|
||||
int us = activeDoc->getProjectUnitSystem();
|
||||
if(us >= 0){//Valid unit system:
|
||||
ui->comboBox_projectUnitSystem->setCurrentIndex( us );
|
||||
int pusIgnore = activeDoc->getProjectUnitSystemIgnore();
|
||||
ui->checkBox_projectUnitSystemIgnore->setChecked( pusIgnore );
|
||||
}else{
|
||||
ui->comboBox_projectUnitSystem->setCurrentIndex( 0 );
|
||||
ui->checkBox_projectUnitSystemIgnore->setChecked( false );
|
||||
}
|
||||
}else{
|
||||
ui->checkBox_projectUnitSystemIgnore->setEnabled(false);
|
||||
ui->comboBox_projectUnitSystem->setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ui->SubstituteDecimal->onRestore();
|
||||
@@ -403,9 +439,11 @@ void DlgGeneralImp::changeEvent(QEvent *event)
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
int index = ui->UseLocaleFormatting->currentIndex();
|
||||
int index2 = ui->comboBox_UnitSystem->currentIndex();
|
||||
int pusIndex = ui->comboBox_projectUnitSystem->currentIndex();
|
||||
ui->retranslateUi(this);
|
||||
ui->UseLocaleFormatting->setCurrentIndex(index);
|
||||
ui->comboBox_UnitSystem->setCurrentIndex(index2);
|
||||
ui->comboBox_projectUnitSystem->setCurrentIndex(pusIndex);
|
||||
}
|
||||
else {
|
||||
QWidget::changeEvent(event);
|
||||
@@ -561,4 +599,17 @@ void DlgGeneralImp::onUnitSystemIndexChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void DlgGeneralImp::on_checkBox_projectUnitSystemIgnore_stateChanged(int state)
|
||||
{
|
||||
if (state < 0)
|
||||
return; // happens when clearing the combo box in retranslateUi()
|
||||
|
||||
// Enable/disable the projectUnitSystem if being ignored:
|
||||
if(state == 2){//ignore
|
||||
ui->comboBox_projectUnitSystem->setEnabled(false);
|
||||
}else if(state == 0){
|
||||
ui->comboBox_projectUnitSystem->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_DlgGeneralImp.cpp"
|
||||
|
||||
@@ -66,6 +66,7 @@ protected Q_SLOTS:
|
||||
|
||||
public Q_SLOTS:
|
||||
void onUnitSystemIndexChanged(int index);
|
||||
void on_checkBox_projectUnitSystemIgnore_stateChanged(int state);
|
||||
|
||||
private:
|
||||
void setRecentFileSize();
|
||||
|
||||
@@ -105,6 +105,9 @@ struct DocumentP
|
||||
std::map<SoSeparator *,ViewProviderDocumentObject*> _CoinMap;
|
||||
std::map<std::string,ViewProvider*> _ViewProviderMapAnnotation;
|
||||
std::list<ViewProviderDocumentObject*> _redoViewProviders;
|
||||
|
||||
int projectUnitSystem=-1;
|
||||
bool projectUnitSystemIgnore;
|
||||
|
||||
using Connection = boost::signals2::connection;
|
||||
Connection connectNewObject;
|
||||
@@ -646,6 +649,30 @@ void Document::setPos(const char* name, const Base::Matrix4D& rclMtrx)
|
||||
|
||||
}
|
||||
|
||||
void Document::setProjectUnitSystem(int pUS)
|
||||
{
|
||||
if(pUS != d->projectUnitSystem && pUS >= 0){
|
||||
d->projectUnitSystem = pUS;
|
||||
setModified(true);
|
||||
}
|
||||
}
|
||||
|
||||
int Document::getProjectUnitSystem() const
|
||||
{
|
||||
return d->projectUnitSystem;
|
||||
}
|
||||
|
||||
void Document::setProjectUnitSystemIgnore(bool ignore)
|
||||
{
|
||||
d->projectUnitSystemIgnore = ignore;
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
bool Document::getProjectUnitSystemIgnore() const
|
||||
{
|
||||
return d->projectUnitSystemIgnore;
|
||||
}
|
||||
|
||||
//*****************************************************************************************************
|
||||
// Document
|
||||
//*****************************************************************************************************
|
||||
@@ -1453,6 +1480,15 @@ void Document::RestoreDocFile(Base::Reader &reader)
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
}
|
||||
try{
|
||||
localreader->readElement("ProjectUnitSystem");
|
||||
int US = localreader->getAttributeAsInteger("US");
|
||||
int ignore = localreader->getAttributeAsInteger("ignore");
|
||||
d->projectUnitSystem = US;
|
||||
d->projectUnitSystemIgnore = ignore;
|
||||
}catch (const Base::XMLParseException& e) {
|
||||
Base::Console().Error("ProjectUnitSystem not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
localreader->readEndElement("Document");
|
||||
@@ -1575,6 +1611,15 @@ void Document::SaveDocFile (Base::Writer &writer) const
|
||||
writer.Stream() << writer.ind() << "<Camera settings=\""
|
||||
<< encodeAttribute(getCameraSettings()) << "\"/>\n";
|
||||
writer.decInd(); // indentation for camera settings
|
||||
|
||||
if( d->projectUnitSystem >= 0 ){
|
||||
writer.incInd(); // indentation for ProjectUnitSystem
|
||||
writer.Stream() << writer.ind() << "<ProjectUnitSystem US=\""
|
||||
<< d->projectUnitSystem << "\" ignore=\""
|
||||
<< d->projectUnitSystemIgnore << "\"/>\n";
|
||||
writer.decInd(); // indentation for ProjectUnitSystem
|
||||
}
|
||||
|
||||
writer.Stream() << "</Document>" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -297,6 +297,12 @@ public:
|
||||
|
||||
const char *getCameraSettings() const;
|
||||
bool saveCameraSettings(const char *) const;
|
||||
|
||||
void setProjectUnitSystem(int);
|
||||
int getProjectUnitSystem() const;
|
||||
|
||||
void setProjectUnitSystemIgnore(bool);
|
||||
bool getProjectUnitSystemIgnore() const;
|
||||
|
||||
protected:
|
||||
// pointer to the python class
|
||||
|
||||
Reference in New Issue
Block a user