Skip to content

Commit

Permalink
Merge branch 'FreeCAD:main' into fontweight
Browse files Browse the repository at this point in the history
  • Loading branch information
obelisk79 authored Feb 12, 2024
2 parents e3c605c + 063bec9 commit 232c2a8
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 51 deletions.
39 changes: 24 additions & 15 deletions src/Mod/AddonManager/install_to_toolbar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

Check warning on line 1 in src/Mod/AddonManager/install_to_toolbar.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

would reformat src/Mod/AddonManager/install_to_toolbar.py
# ***************************************************************************
# * *
# * Copyright (c) 2022-2023 FreeCAD Project Association *
# * Copyright (c) 2022-2024 The FreeCAD Project Association AISBL *
# * *
# * This file is part of FreeCAD. *
# * *
Expand Down Expand Up @@ -217,6 +217,28 @@ def install_toolbar_button(repo: Addon) -> None:
FreeCAD.Console.PrintMessage("In the end, no custom toolbar was set, bailing out\n")


def find_installed_icon(repo: Addon) -> str:
"""The icon the macro specifies is usually not the actual installed icon, but rather a cached
copy. This function looks for a file with the same name located in the macro installation
path."""
macro_repo_dir = FreeCAD.getUserMacroDir(True)
if repo.macro.icon:

Check warning on line 225 in src/Mod/AddonManager/install_to_toolbar.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
basename = os.path.basename(repo.macro.icon)
# Simple case first: the file is just in the macro directory...
if os.path.isfile(os.path.join(macro_repo_dir, basename)):
return os.path.join(macro_repo_dir, basename)
# More complex: search for it
for root, dirs, files in os.walk(macro_repo_dir):

Check warning on line 231 in src/Mod/AddonManager/install_to_toolbar.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Unused variable 'dirs' (unused-variable)
for name in files:
if name == basename:
return os.path.join(root, name)
return ""
elif repo.macro.xpm:
return os.path.normpath(os.path.join(macro_repo_dir, repo.macro.name + "_icon.xpm"))
else:
return ""


def install_macro_to_toolbar(repo: Addon, toolbar: object) -> None:
"""Adds an icon for the given macro to the given toolbar."""
menuText = repo.display_name
Expand All @@ -233,20 +255,7 @@ def install_macro_to_toolbar(repo: Addon, toolbar: object) -> None:
+ " "
+ repo.display_name
)
if repo.macro.icon:
if os.path.isabs(repo.macro.icon):
pixmapText = os.path.normpath(repo.macro.icon)
else:
macro_repo_dir = FreeCAD.getUserMacroDir(True)
pixmapText = os.path.normpath(os.path.join(macro_repo_dir, repo.macro.icon))
elif repo.macro.xpm:
macro_repo_dir = FreeCAD.getUserMacroDir(True)
icon_file = os.path.normpath(os.path.join(macro_repo_dir, repo.macro.name + "_icon.xpm"))
with open(icon_file, "w", encoding="utf-8") as f:
f.write(repo.macro.xpm)
pixmapText = icon_file
else:
pixmapText = None
pixmapText = find_installed_icon(repo)

# Add this command to that toolbar
command_name = FreeCADGui.Command.createCustomCommand(
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def onBeforeChange(self,obj,prop):

if prop in ["Base","WindowParts","Placement","HoleDepth","Height","Width","Hosts"]:
setattr(self,prop,getattr(obj,prop))
if prop in ["Height","Width"]:
if prop in ["Height","Width"] and obj.CloneOf is None:
self.TouchOnShapeChange = True # touch hosts after next "Shape" change

def onChanged(self,obj,prop):
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Arch/importIFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
if clone.Shape.Solids:
s2 = clone.Shape.Solids[0]
else:
s1 = clone.Shape
s2 = clone.Shape
if hasattr(s1,"CenterOfMass") and hasattr(s2,"CenterOfMass"):
v = s1.CenterOfMass.sub(s2.CenterOfMass)
if product.Representation:
Expand Down Expand Up @@ -671,10 +671,13 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
obj.Width = 0
obj.Length = 0
if (freecadtype in ["Rebar"]) and baseobj:
# TODO rebars don't keep link to their baee object - we can remove it
# TODO rebars don't keep link to their base object - we can remove it
bn = baseobj.Name
doc.removeObject(bn)
if store:
# Recompute required otherwise obj has a null shape and then
# cloning distances cannot be determined in the next loop.
obj.recompute()
sharedobjects[store] = obj

# set the placement from the storey's elevation property
Expand Down
10 changes: 8 additions & 2 deletions src/Mod/Help/Help.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,14 @@ def get_location(page):
elif PREFS.GetBool("optionCustom", False):
location = PREFS.GetString("Location", "")
if not location:
location = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "Documentation", "wiki")
location += page + "md"
location = os.path.join(
FreeCAD.getUserAppDataDir(),
"Mod",
"offline-documentation",
"FreeCAD-documentation-main",
"wiki",
)
location = os.path.join(location, page + ".md")
return location


Expand Down
11 changes: 7 additions & 4 deletions src/Mod/Help/dlgPreferencesHelp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ This is currently not available...</string>
<property name="toolTip">
<string>Set this to a custom URL or the folder where the help files are located.
You can easily download the documentation for offline use by using the Addon
Manager and installing the &quot;offline documentation&quot; addon. If this
Manager and installing the &quot;offline-documentation&quot; addon. If this
field is left blank, FreeCAD will automatically search for the help files at
the default location ($USERAPPDATADIR/Mod/Documentation).</string>
the default location ($USERAPPDATADIR/Mod/offline-documentation).</string>
</property>
<property name="text">
<string>Custom location</string>
Expand Down Expand Up @@ -82,12 +82,15 @@ to get French translation of the documentation.</string>
</item>
<item row="6" column="1">
<widget class="Gui::PrefFileChooser" name="fileChooser">
<property name="mode">
<enum>Gui::FileChooser::Directory</enum>
</property>
<property name="toolTip">
<string>Set this to a custom URL or the folder where the help files are located.
You can easily download the documentation for offline use by using the Addon
Manager and installing the &quot;offline documentation&quot; addon. If this
Manager and installing the &quot;offline-documentation&quot; addon. If this
field is left blank, FreeCAD will automatically search for the help files at
the default location ($USERAPPDATADIR/Mod/Documentation).</string>
the default location ($USERAPPDATADIR/Mod/offline-documentation).</string>
</property>
<property name="fileName">
<string/>
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/TechDraw/App/DrawView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ bool DrawView::isInClip()
return false;
}

DrawView *DrawView::claimParent() const
{
return nullptr;
}

DrawViewClip* DrawView::getClipGroup()
{
std::vector<App::DocumentObject*> parent = getInList();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawView.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class TechDrawExport DrawView : public App::DocumentObject

virtual DrawPage* findParentPage() const;
virtual std::vector<DrawPage*> findAllParentPages() const;
virtual DrawView *claimParent() const;

virtual int countParentPages() const;
virtual QRectF getRect() const; //must be overridden by derived class
QRectF getRectAligned() const;
Expand Down
46 changes: 46 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,38 @@ DrawViewSymbol::DrawViewSymbol()
ADD_PROPERTY_TYPE(Symbol, (""), vgroup, App::Prop_None, "The SVG code defining this symbol");
ADD_PROPERTY_TYPE(EditableTexts, (""), vgroup, App::Prop_None,
"Substitution values for the editable strings in this symbol");
ADD_PROPERTY_TYPE(Owner, (nullptr), vgroup, (App::PropertyType)(App::Prop_None),
"Feature to which this symbol is attached");

ScaleType.setValue("Custom");
Scale.setStatus(App::Property::ReadOnly, false);
Symbol.setStatus(App::Property::Hidden, true);
}

DrawViewSymbol::~DrawViewSymbol() {}

void DrawViewSymbol::touchTreeOwner()
{
auto owner = dynamic_cast<DrawView *>(Owner.getValue());
if (owner) {
owner->touch();
}
else { // If no owner is specified, touch all parent pages
for (auto page : findAllParentPages()) {
page->touch();
}
}
}

void DrawViewSymbol::onBeforeChange(const App::Property *prop)
{
if (prop == &Owner && !isRestoring()) {
touchTreeOwner();
}

TechDraw::DrawView::onBeforeChange(prop);
}

void DrawViewSymbol::onChanged(const App::Property* prop)
{
if (prop == &Symbol) {
Expand All @@ -72,17 +97,38 @@ void DrawViewSymbol::onChanged(const App::Property* prop)
//1 cycle
updateFieldsInSymbol();
}
else if (prop == &Owner) {
if (!isRestoring()) {
touchTreeOwner();
}
}

TechDraw::DrawView::onChanged(prop);
}

short DrawViewSymbol::mustExecute() const
{
if (!isRestoring()) {
if (Owner.isTouched()) {
return 1;
}
}

return DrawView::mustExecute();
}

App::DocumentObjectExecReturn* DrawViewSymbol::execute()
{
//nothing to do. DVS is just a container for properties.
//the action takes place on the Gui side.
return DrawView::execute();
}

DrawView *DrawViewSymbol::claimParent() const
{
return dynamic_cast<DrawView *>(Owner.getValue());
}

QRectF DrawViewSymbol::getRect() const
{
double w = 64.0;//must default to something
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class TechDrawExport DrawViewSymbol : public TechDraw::DrawView

App::PropertyString Symbol;
App::PropertyStringList EditableTexts;
App::PropertyLink Owner;

short mustExecute() const override;
/** @name methods override Feature */
//@{
/// recalculate the Feature
Expand All @@ -59,13 +61,16 @@ class TechDrawExport DrawViewSymbol : public TechDraw::DrawView
const char* getViewProviderName() const override {
return "TechDrawGui::ViewProviderSymbol";
}
DrawView *claimParent(void) const override;
QRectF getRect() const override;
bool checkFit(TechDraw::DrawPage* p) const override;

//return PyObject as DrawViewSymbolPy
PyObject *getPyObject() override;

protected:
void touchTreeOwner();
void onBeforeChange(const App::Property* prop) override;
void onChanged(const App::Property* prop) override;
Base::BoundBox3d bbox;

Expand Down
10 changes: 10 additions & 0 deletions src/Mod/TechDraw/App/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepExtrema_DistShapeShape.hxx>
# include <BRepGProp.hxx>
# include <BRepLib.hxx>
# include <BRepLProp_CLProps.hxx>
# include <BRepTools.hxx>
# include <GC_MakeArcOfCircle.hxx>
# include <GC_MakeEllipse.hxx>
# include <gce_MakeCirc.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <GProp_GProps.hxx>
# include <Geom_BSplineCurve.hxx>
# include <Geom_BezierCurve.hxx>
# include <Geom_Circle.hxx>
Expand Down Expand Up @@ -158,6 +160,14 @@ TopoDS_Face Face::toOccFace() const
return TopoDS_Face();
}

//**** Face
Base::Vector3d Face::getCenter() const {
GProp_GProps faceProps;
BRepGProp::SurfaceProperties(toOccFace(), faceProps);

return DrawUtil::toVector3d(faceProps.CentreOfMass());
}

Face::~Face()
{
for(auto it : wires) {
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ class TechDrawExport Face
~Face();
TopoDS_Face toOccFace() const;
std::vector<Wire *> wires;

Base::Vector3d getCenter() const;
};
using FacePtr = std::shared_ptr<Face>;

Expand Down
37 changes: 29 additions & 8 deletions src/Mod/TechDraw/Gui/CommandAnnotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewAnnotation.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawViewSymbol.h>
#include <Mod/TechDraw/App/DrawWeldSymbol.h>
#include <Mod/TechDraw/App/DrawUtil.h>

Expand Down Expand Up @@ -1618,19 +1619,39 @@ CmdTechDrawSurfaceFinishSymbols::CmdTechDrawSurfaceFinishSymbols()
void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
{
Q_UNUSED(iMsg);

std::string ownerName;
std::vector<Gui::SelectionObject> selection = this->getSelection().getSelectionEx();
if (selection.empty())
{
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"), QObject::tr("Selection is empty"));
return;
TechDraw::DrawPage *page = DrawGuiUtil::findPage(this);
if (!page) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
QObject::tr("No page to insert the symbol!"));
return;
}

ownerName = page->getNameInDocument();
}
TechDraw::DrawViewPart* objFeat = dynamic_cast<TechDraw::DrawViewPart*> (selection[0].getObject());
if(!objFeat)
{
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"), QObject::tr("No object selected"));
return;
else {
auto objFeat = dynamic_cast<TechDraw::DrawView *>(selection.front().getObject());
if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())
&& !objFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
QObject::tr("Selected object is not a part view, nor a leader line"));
return;
}

ownerName = objFeat->getNameInDocument();

const std::vector<std::string> &subNames = selection.front().getSubNames();
if (!subNames.empty()) {
ownerName += '.';
ownerName += subNames.front();
}
}
Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(objFeat));

Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(ownerName));
}

bool CmdTechDrawSurfaceFinishSymbols::isActive()
Expand Down
20 changes: 20 additions & 0 deletions src/Mod/TechDraw/Gui/QGIView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,26 @@ void QGIView::addArbitraryItem(QGraphicsItem* qgi)
}
}

void QGIView::switchParentItem(QGIView *targetParent)
{
auto currentParent = dynamic_cast<QGIView *>(this->parentItem());
if (currentParent != targetParent) {
if (targetParent) {
targetParent->addToGroup(this);
}
else {
currentParent->removeFromGroup(this);
}

if (currentParent) {
currentParent->updateView();
}
if (targetParent) {
targetParent->updateView();
}
}
}

void QGIView::setStack(int z)
{
m_zOrder = z;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ class TechDrawGuiExport QGIView : public QObject, public QGraphicsItemGroup
static int exactFontSize(std::string fontFamily, double nominalSize);

virtual void removeChild(QGIView* child);

virtual void addArbitraryItem(QGraphicsItem* qgi);
virtual void switchParentItem(QGIView *targetParent);

// Mouse handling
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
Expand Down
Loading

0 comments on commit 232c2a8

Please sign in to comment.