Skip to content

Commit

Permalink
Gsoc2023 measure (#3)
Browse files Browse the repository at this point in the history
* checkpoint - fix warnings, add tooltip, check for valid shape

* checkpoint - remove warnings

* checkpoint - parent properties to children

* checkpoint - get initial property values from config

* checkpoint - add preference getters

* checkpoint - inheritance & property init

* checkpoint - add Appearance pref page

* checkpoint - use prefs for default values

* checkpoint - move vpMeasurementBase to MeasureGui

---------

Co-authored-by: wandererfan <[email protected]>
  • Loading branch information
hlorus and WandererFan authored Sep 14, 2023
1 parent 9a47907 commit ebce989
Show file tree
Hide file tree
Showing 23 changed files with 1,307 additions and 57 deletions.
1 change: 0 additions & 1 deletion src/Gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#include "ViewProviderLinkPy.h"
#include "ViewProviderMaterialObject.h"
#include "ViewProviderMeasureDistance.h"
#include "ViewProviderMeasurementBase.h"
#include "ViewProviderOrigin.h"
#include "ViewProviderOriginFeature.h"
#include "ViewProviderOriginGroup.h"
Expand Down
2 changes: 0 additions & 2 deletions src/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ SET(Viewprovider_CPP_SRCS
ViewProviderGeometryObject.cpp
ViewProviderImagePlane.cpp
ViewProviderInventorObject.cpp
ViewProviderMeasurementBase.cpp
ViewProviderMeasureDistance.cpp
ViewProviderPyImp.cpp
ViewProviderPythonFeature.cpp
Expand Down Expand Up @@ -938,7 +937,6 @@ SET(Viewprovider_SRCS
ViewProviderGeometryObject.h
ViewProviderImagePlane.h
ViewProviderInventorObject.h
ViewProviderMeasurementBase.h
ViewProviderMeasureDistance.h
ViewProviderPythonFeature.h
ViewProviderVRMLObject.h
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Measure/App/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ SET(MeasureModule_SRCS
Measure.h
PreCompiled.cpp
PreCompiled.h
Preferences.cpp
Preferences.h
)

SOURCE_GROUP("Module" FILES ${MeasureModule_SRCS})
Expand Down
74 changes: 74 additions & 0 deletions src/Mod/Measure/App/Preferences.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/***************************************************************************
* Copyright (c) 2023 WandererFan <[email protected]> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/

#include "PreCompiled.h"
#ifndef _PreComp_
# include <string>
#endif

#include <App/Application.h>
#include <App/Material.h>
#include <Base/Console.h>
#include <Base/Parameter.h>

#include "Preferences.h"


//getters for parameters used in multiple places.
//ensure this is in sync with parameter names and default values on preference pages

using namespace Measure;

//! Returns the Measure preference group
Base::Reference<ParameterGrp> Preferences::getPreferenceGroup(const char* Name)
{
return App::GetApplication().GetUserParameter().GetGroup("BaseApp/Preferences/Mod/Measure")->GetGroup(Name);
}

App::Color Preferences::defaultLineColor()
{
App::Color fcColor;
fcColor.setPackedValue(getPreferenceGroup("Appearance")->GetUnsigned("DefaultLineColor", 0xFFFFFFFF));
return fcColor;
}

App::Color Preferences::defaultTextColor()
{
App::Color fcColor;
fcColor.setPackedValue(getPreferenceGroup("Appearance")->GetUnsigned("DefaultTextColor", 0xFFFFFFFF));
return fcColor;
}

double Preferences::defaultDistFactor()
{
return getPreferenceGroup("Appearance")->GetFloat("DefaultDistFactor", 1.0);
}

int Preferences::defaultFontSize()
{
return getPreferenceGroup("Appearance")->GetInt("DefaultFontSize", 0);
}

bool Preferences::defaultMirror()
{
return getPreferenceGroup("Appearance")->GetBool("DefaultMirror", false);
}
57 changes: 57 additions & 0 deletions src/Mod/Measure/App/Preferences.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/***************************************************************************
* Copyright (c) 2023 WandererFan <[email protected]> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/

#ifndef Preferences_h_
#define Preferences_h_

#include <string>

#include <Base/Parameter.h>
#include <Mod/Measure/MeasureGlobal.h>


namespace App
{
class Color;
}

namespace Measure
{

//getters for parameters used in multiple places.
class MeasureExport Preferences
{

public:
static Base::Reference<ParameterGrp> getPreferenceGroup(const char* Name);

static App::Color defaultLineColor();
static App::Color defaultTextColor();
static double defaultDistFactor();
static int defaultFontSize();
static bool defaultMirror();
};


}//end namespace Measure
#endif

1 change: 1 addition & 0 deletions src/Mod/Measure/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_subdirectory(App)
set(Measure_Scripts
Init.py
)

if(BUILD_GUI)
list(APPEND Measure_Scripts InitGui.py)
add_subdirectory(Gui)
Expand Down
24 changes: 17 additions & 7 deletions src/Mod/Measure/Gui/AppMeasureGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Base/PyObjectBase.h>
#include <Base/Tools.h>
#include <Gui/Application.h>
#include <Gui/Language/Translator.h>
#include <Gui/WidgetFactory.h>

#include "ViewProviderMeasureDistancePoints.h"
#include "DlgPrefsMeasureAppearanceImp.h"
#include "ViewProviderMeasureAngle.h"
#include <Mod/Measure/Gui/ViewProviderMeasureDistance.h>

#include "ViewProviderMeasureDistancePoints.h"
#include "ViewProviderMeasureDistance.h"
#include "ViewProviderMeasurementBase.h"


// use a different name to CreateCommand()
Expand Down Expand Up @@ -79,15 +83,21 @@ PyMOD_INIT_FUNC(MeasureGui)
PyMOD_Return(nullptr);
}

PyObject* mod = MeasureGui::initModule();
Base::Console().Log("Loading GUI of Measure module... done\n");

// instantiating the commands
CreateMeasureCommands();

MeasureGui::ViewProviderMeasurementBase ::init();
MeasureGui::ViewProviderMeasureDistancePoints ::init();
MeasureGui::ViewProviderMeasureAngle ::init();
MeasureGui::ViewProviderMeasureDistance ::init();

// instantiating the commands
CreateMeasureCommands();
// register preferences pages
new Gui::PrefPageProducer<MeasureGui::DlgPrefsMeasureAppearanceImp>(QT_TRANSLATE_NOOP("QObject", "Measure"));

// Q_INIT_RESOURCE(Measure);

PyObject* mod = MeasureGui::initModule();
Base::Console().Log("Loading GUI of Measure module... done\n");
PyMOD_Return(mod);
}
40 changes: 32 additions & 8 deletions src/Mod/Measure/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ set(MeasureGui_LIBS
FreeCADGui
)

set (Measure_TR_QRC ${CMAKE_CURRENT_BINARY_DIR}/Resources/Measure_translation.qrc)
qt_find_and_add_translation(QM_SRCS "Resources/translations/*_*.ts"
${CMAKE_CURRENT_BINARY_DIR}/Resources/translations)
qt_create_resource_file(${Measure_TR_QRC} ${QM_SRCS})
qt_add_resources(MeasureGui_SRCS Resources/Measure.qrc ${Measure_TR_QRC})

SET(MeasureGui_UIC_SRCS
DlgPrefsMeasureAppearanceImp.ui
)

SET(MeasureGui_SRCS
${Measure_QRC_SRCS}
# ${MeasureGui_UIC_SRCS}
# DlgMeasurePreferences.ui
# DlgMeasurePreferencesImp.cpp
# DlgMeasurePreferencesImp.h
${CMAKE_SOURCE_DIR}/src/Mod/Measure/InitGui.py
${MeasureGui_SRCS}
AppMeasureGui.cpp
Command.cpp
Resources/Measure.qrc
PreCompiled.cpp
PreCompiled.h
ViewProviderMeasurementBase.cpp
ViewProviderMeasurementBase.h
ViewProviderMeasureDistancePoints.cpp
ViewProviderMeasureDistancePoints.h
ViewProviderMeasureAngle.cpp
Expand All @@ -32,21 +41,36 @@ SET(MeasureGui_SRCS
ViewProviderMeasureDistance.h
# Workbench.cpp
# Workbench.h
DlgPrefsMeasureAppearanceImp.ui
DlgPrefsMeasureAppearanceImp.cpp
DlgPrefsMeasureAppearanceImp.h

Check warning on line 47 in src/Mod/Measure/Gui/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Lint / Lint

<-- trailing whitespace
)

SET(MeasureGuiTaskDlgs_SRCS
DlgPrefsMeasureAppearanceImp.ui
)

set(MeasureGui_Scripts
../InitGui.py
SET(MeasureGuiIcon_SVG
Resources/icons/preferences-measure.svg
)

#set(MeasureGui_Scripts
# ../InitGui.py
#)

if(FREECAD_USE_PCH)
add_definitions(-D_PreComp_)
GET_MSVC_PRECOMPILED_SOURCE("PreCompiled.cpp" PCH_SRCS ${MeasureGui_SRCS})
ADD_MSVC_PRECOMPILED_HEADER(MeasureGui PreCompiled.h PreCompiled.cpp PCH_SRCS)
endif(FREECAD_USE_PCH)

add_library(MeasureGui SHARED ${MeasureGui_SRCS} ${MeasureGui_Scripts}) # ${MeasureGuiIcon_SVG}
add_library(MeasureGui SHARED ${MeasureGui_SRCS} ${MeasureGuiIcon_SVG})
target_link_libraries(MeasureGui ${MeasureGui_LIBS})

fc_copy_sources(MeasureGui "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Measure/" ${MeasureGuiIcon_SVG})
INSTALL(FILES ${MeasureGuiIcon_SVG} DESTINATION "${CMAKE_INSTALL_DATADIR}/Mod/Measure/Resources/icons")

SET_BIN_DIR(MeasureGui MeasureGui /Mod/Measure)
SET_PYTHON_PREFIX_SUFFIX(MeasureGui)

Expand Down
76 changes: 76 additions & 0 deletions src/Mod/Measure/Gui/DlgPrefsMeasureAppearanceImp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**************************************************************************
* Copyright (c) 2023 Wanderer Fan <[email protected]> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/

#include "PreCompiled.h"

#include "DlgPrefsMeasureAppearanceImp.h"
#include "ui_DlgPrefsMeasureAppearanceImp.h"

Check failure on line 26 in src/Mod/Measure/Gui/DlgPrefsMeasureAppearanceImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'ui_DlgPrefsMeasureAppearanceImp.h' file not found [clang-diagnostic-error]

using namespace MeasureGui;

DlgPrefsMeasureAppearanceImp::DlgPrefsMeasureAppearanceImp( QWidget* parent )
: PreferencePage( parent )
, ui(new Ui_DlgPrefsMeasureAppearanceImp)
{
ui->setupUi(this);
}

DlgPrefsMeasureAppearanceImp::~DlgPrefsMeasureAppearanceImp()
{
// no need to delete child widgets, Qt does it all for us
}

void DlgPrefsMeasureAppearanceImp::saveSettings()
{
ui->cbMirror->onSave();
ui->dsbDistFactor->onSave();
ui->sbFontSize->onSave();
ui->cbText->onSave();
ui->cbLine->onSave();
}

void DlgPrefsMeasureAppearanceImp::loadSettings()
{
ui->sbFontSize->onRestore();
ui->cbText->onRestore();
ui->cbLine->onRestore();
ui->cbMirror->onRestore();
ui->dsbDistFactor->onRestore();
}

/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgPrefsMeasureAppearanceImp::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
saveSettings();
ui->retranslateUi(this);
loadSettings();
}
else {
QWidget::changeEvent(e);
}
}

#include <Mod/Measure/Gui/moc_DlgPrefsMeasureAppearanceImp.cpp>

Loading

0 comments on commit ebce989

Please sign in to comment.