Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorus committed Sep 17, 2024
2 parents ffa926c + 758674d commit b8fddd1
Show file tree
Hide file tree
Showing 52 changed files with 2,250 additions and 344 deletions.
1 change: 1 addition & 0 deletions src/App/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@ Document::readObjects(Base::XMLReader& reader)

void Document::addRecomputeObject(DocumentObject *obj) {
if(testStatus(Status::Restoring) && obj) {
setStatus(Status::RecomputeOnRestore, true);
d->touchedObjs.insert(obj);
obj->touch();
}
Expand Down
1 change: 1 addition & 0 deletions src/App/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AppExport Document : public App::PropertyContainer
RestoreError = 10,
LinkStampChanged = 11, // Indicates during restore time if any linked document's time stamp has changed
IgnoreErrorOnRecompute = 12, // Don't report errors if the recompute failed
RecomputeOnRestore = 13, // Mark pending recompute on restore for migration purposes
};

/** @name Properties */
Expand Down
44 changes: 43 additions & 1 deletion src/Gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,9 @@ Application::Application(bool GUIenabled)
std::bind(&Gui::Application::slotRelabelDocument, this, sp::_1));
App::GetApplication().signalShowHidden.connect(
std::bind(&Gui::Application::slotShowHidden, this, sp::_1));
App::GetApplication().signalFinishRestoreDocument.connect(
std::bind(&Gui::Application::slotFinishRestoreDocument, this, sp::_1));
// NOLINTEND

// install the last active language
ParameterGrp::handle hPGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp");
hPGrp = hPGrp->GetGroup("Preferences")->GetGroup("General");
Expand Down Expand Up @@ -978,6 +979,47 @@ void Application::slotShowHidden(const App::Document& Doc)
signalShowHidden(*doc->second);
}

void Application::slotFinishRestoreDocument([[maybe_unused]] const App::Document& Doc) {
// Quietly gnore the doc parameter and check across all documents.
std::vector<App::Document *> docs;
for (auto doc: App::GetApplication().getDocuments()) {
if (doc->testStatus(App::Document::RecomputeOnRestore)) {
docs.push_back(doc);
doc->setStatus(App::Document::RecomputeOnRestore, false);
}
}
// Certain tests want to use very old .FCStd files. We should not prompt during those tests, so this
// allows them to 'FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")`
const std::map<std::string, std::string>& Map = App::Application::Config();
auto value = Map.find("SuppressRecomputeRequiredDialog");
bool skip = value not_eq Map.end() and not value->second.empty(); // Any non empty string is true.
if (docs.empty() || skip )
return;
WaitCursor wc;
wc.restoreCursor();
auto res = QMessageBox::warning(getMainWindow(), QObject::tr("Recomputation required"),
QObject::tr("Some document(s) require recomputation for migration purposes. "
"It is highly recommended to perform a recomputation before "
"any modification to avoid compatibility problems.\n\n"
"Do you want to recompute now?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (res != QMessageBox::Yes)
return;
bool hasError = false;
for (auto doc: App::Document::getDependentDocuments(docs, true)) {
try {
doc->recompute({}, false, &hasError);
} catch (Base::Exception &e) {
e.ReportException();
hasError = true;
}
}
if (hasError)
QMessageBox::critical(getMainWindow(), QObject::tr("Recompute error"),
QObject::tr("Failed to recompute some document(s).\n"
"Please check report view for more details."));
}

void Application::slotActiveDocument(const App::Document& Doc)
{
std::map<const App::Document*, Gui::Document*>::iterator doc = d->documents.find(&Doc);
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class GuiExport Application
boost::signals2::signal<void ()> signalRefreshWorkbenches;
/// signal on show hidden items
boost::signals2::signal<void (const Gui::Document&)> signalShowHidden;
/// signal on document restore complete
boost::signals2::signal<void (const Gui::Document&)> signalFinishRestoreDocument;
/// signal on activating view
boost::signals2::signal<void (const Gui::MDIView*)> signalActivateView;
/// signal on entering in edit mode
Expand All @@ -151,6 +153,7 @@ class GuiExport Application
void slotRenameDocument(const App::Document&);
void slotActiveDocument(const App::Document&);
void slotShowHidden(const App::Document&);
void slotFinishRestoreDocument(const App::Document&);
void slotNewObject(const ViewProvider&);
void slotDeletedObject(const ViewProvider&);
void slotChangedObject(const ViewProvider&, const App::Property& Prop);
Expand Down
1 change: 1 addition & 0 deletions src/Gui/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct DocumentP
Connection connectStartLoadDocument;
Connection connectFinishLoadDocument;
Connection connectShowHidden;
Connection connectFinishRestoreDocument;
Connection connectFinishRestoreObject;
Connection connectExportObjects;
Connection connectImportObjects;
Expand Down
Binary file modified src/Gui/Icons/freecadabout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Gui/PreferencePages/DlgSettingsNavigation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<property name="maximumSize">
<size>
<width>240</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
Expand Down
13 changes: 2 additions & 11 deletions src/Main/MainCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,8 @@ using App::Application;
using Base::Console;

const char sBanner[] =
"(c) Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2024\n"
"FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n"
"FreeCAD wouldn't be possible without FreeCAD community.\n"
" ##### #### ### #### \n"
" # # # # # # \n"
" # ## #### #### # # # # # \n"
" #### # # # # # # # ##### # # \n"
" # # #### #### # # # # # \n"
" # # # # # # # # # ## ## ##\n"
" # # #### #### ### # # #### ## ## ##\n\n";

"(C) 2001-2024 FreeCAD contributors\n"
"FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n\n";

int main(int argc, char** argv)
{
Expand Down
12 changes: 2 additions & 10 deletions src/Main/MainGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,8 @@
void PrintInitHelp();

const char sBanner[] =
"\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2024\n"
"FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n"
"FreeCAD wouldn't be possible without FreeCAD community.\n"
" ##### #### ### #### \n"
" # # # # # # \n"
" # ## #### #### # # # # # \n"
" #### # # # # # # # ##### # # \n"
" # # #### #### # # # # # \n"
" # # # # # # # # # ## ## ##\n"
" # # #### #### ### # # #### ## ## ##\n\n";
"(C) 2001-2024 FreeCAD contributors\n"
"FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n\n";

#if defined(_MSC_VER)
void InitMiniDumpWriter(const std::string&);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/BIM/ArchMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def reject(self):

def chooseMat(self, card):
"sets self.material from a card"
card = self.form.comboBox_MaterialsInDir.currentText()
if card in self.cards:
import importFCMat
self.material = importFCMat.read(self.cards[card])
Expand Down
6 changes: 2 additions & 4 deletions src/Mod/BIM/bimcommands/BimWelcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ def GetResources(self):
def Activated(self):
from PySide import QtCore, QtGui

# load dialog
self.form = FreeCADGui.PySideUic.loadUi(":ui/dialogWelcome.ui")

# set the title image
self.form.image.setPixmap(QtGui.QPixmap(":/icons/banner.png"))

# handle the tutorial links
self.form.label_4.linkActivated.connect(self.handleLink)
self.form.label_7.linkActivated.connect(self.handleLink)

self.form.adjustSize()

# center the dialog over FreeCAD window
mw = FreeCADGui.getMainWindow()
self.form.move(
Expand Down
15 changes: 7 additions & 8 deletions src/Mod/BIM/importers/exportIFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
__author__ = ("Yorik van Havre", "Jonathan Wiedemann", "Bernd Hahnebach")
__url__ = "https://www.freecad.org"

PARAMS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")

# Templates and other definitions ****
# Specific FreeCAD <-> IFC slang translations
translationtable = {
Expand Down Expand Up @@ -172,12 +174,9 @@ def getPreferences():
# set schema
if hasattr(ifcopenshell, "schema_identifier"):
schema = ifcopenshell.schema_identifier
elif ifcos_version >= 0.6:
# v0.6 onwards allows to set our own schema
schema = ["IFC4", "IFC2X3"][params.get_param_arch("IfcVersion")]
else:
schema = "IFC2X3"

# v0.6 onwards allows to set our own schema
schema = PARAMS.GetString("DefaultIfcExportVersion", "IFC4")
preferences["SCHEMA"] = schema

return preferences
Expand Down Expand Up @@ -308,9 +307,9 @@ def export(exportList, filename, colors=None, preferences=None):
project = contextCreator.project
objectslist = [obj for obj in objectslist if obj != contextCreator.project_object]

if Draft.getObjectsOfType(objectslist, "Site"): # we assume one site and one representation context only
decl = Draft.getObjectsOfType(objectslist, "Site")[0].Declination.getValueAs(FreeCAD.Units.Radian)
contextCreator.model_context.TrueNorth.DirectionRatios = (math.cos(decl+math.pi/2), math.sin(decl+math.pi/2))
if Draft.getObjectsOfType(objectslist, "Site"): # we assume one site and one representation context only
decl = Draft.getObjectsOfType(objectslist, "Site")[0].Declination.getValueAs(FreeCAD.Units.Radian)
contextCreator.model_context.TrueNorth.DirectionRatios = (math.cos(decl+math.pi/2), math.sin(decl+math.pi/2))

# reusable entity system

Expand Down
48 changes: 38 additions & 10 deletions src/Mod/BIM/nativeifc/ifc_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import multiprocessing
import FreeCADGui
from pivy import coin
from PySide import QtCore


def generate_geometry(obj, cached=False):
Expand Down Expand Up @@ -76,6 +77,7 @@ def generate_geometry(obj, cached=False):
elif obj.ViewObject and obj.ShapeMode == "Coin":
node, placement = generate_coin(ifcfile, elements, cached)
if node:
#QtCore.QTimer.singleShot(0, lambda: set_representation(obj.ViewObject, node))
set_representation(obj.ViewObject, node)
colors = node[0]
else:
Expand All @@ -86,7 +88,7 @@ def generate_geometry(obj, cached=False):

# set shape and diffuse colors
if colors:
ifc_tools.set_colors(obj, colors) # TODO migrate here?
QtCore.QTimer.singleShot(0, lambda: ifc_tools.set_colors(obj, colors)) # TODO migrate here?


def generate_shape(ifcfile, elements, cached=False):
Expand Down Expand Up @@ -140,7 +142,12 @@ def generate_shape(ifcfile, elements, cached=False):
brep = item.geometry.brep_data
shape = Part.Shape()
shape.importBrepFromString(brep, False)
mat = ifc_tools.get_freecad_matrix(item.transformation.matrix.data)
if hasattr(item.transformation.matrix, "data"):
# IfcOpenShell 0.7
mat = ifc_tools.get_freecad_matrix(item.transformation.matrix.data)
else:
# IfcOpenShell 0.8
mat = ifc_tools.get_freecad_matrix(item.transformation.matrix)
shape.scale(ifc_tools.SCALE)
shape.transformShape(mat)
shapes.append(shape)
Expand Down Expand Up @@ -248,15 +255,25 @@ def generate_coin(ifcfile, elements, cached=False):
# colors
if item.geometry.materials:
color = item.geometry.materials[0].diffuse
color = (float(color[0]), float(color[1]), float(color[2]))
if hasattr(color, "r") and hasattr(color, "g"):
# IfcOpenShell 0.8
color = (color.r(), color.g(), color.b())
else:
# IfcOpenShell 0.7
color = (float(color[0]), float(color[1]), float(color[2]))
trans = item.geometry.materials[0].transparency
if trans >= 0:
color += (float(trans),)
else:
color = (0.85, 0.85, 0.85)

# verts
matrix = ifc_tools.get_freecad_matrix(item.transformation.matrix.data)
if hasattr(item.transformation.matrix, "data"):
# IfcOpenShell 0.7
matrix = ifc_tools.get_freecad_matrix(item.transformation.matrix.data)
else:
# IfcOpenShell 0.8
matrix = ifc_tools.get_freecad_matrix(item.transformation.matrix)
placement = FreeCAD.Placement(matrix)
verts = item.geometry.verts
verts = [FreeCAD.Vector(verts[i : i + 3]) for i in range(0, len(verts), 3)]
Expand Down Expand Up @@ -361,13 +378,24 @@ def get_geom_iterator(ifcfile, elements, brep_mode):
if we want brep data or not"""

settings = ifcopenshell.geom.settings()
if brep_mode:
settings.set(settings.DISABLE_TRIANGULATION, True)
settings.set(settings.USE_BREP_DATA, True)
settings.set(settings.SEW_SHELLS, True)
body_contexts = ifc_tools.get_body_context_ids(ifcfile) # TODO migrate here?
if body_contexts:
settings.set_context_ids(body_contexts)
if brep_mode:
if hasattr(settings, "DISABLE_TRIANGULATION"):
# IfcOpenShell 0.7
settings.set(settings.DISABLE_TRIANGULATION, True)
settings.set(settings.USE_BREP_DATA, True)
settings.set(settings.SEW_SHELLS, True)
if body_contexts:
settings.set_context_ids(body_contexts)
elif hasattr(settings, "ITERATOR_OUTPUT"):
# IfcOpenShell 0.8
settings.set("ITERATOR_OUTPUT", ifcopenshell.ifcopenshell_wrapper.SERIALIZED)
if body_contexts:
# Is this the right way? It works, but not sure.
settings.set("CONTEXT_IDENTIFIERS", [str(s) for s in body_contexts])
else:
# We print a debug message but we continue
print("DEBUG: ifc_tools.get_geom_iterator: Iterator could not be set up correctly")
cores = multiprocessing.cpu_count()
iterator = ifcopenshell.geom.iterator(settings, ifcfile, cores, include=elements)
if not iterator.initialize():
Expand Down
7 changes: 6 additions & 1 deletion src/Mod/BIM/nativeifc/ifc_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def create_layer(name, project):

group = ifc_tools.get_group(project, "IfcLayersGroup")
ifcfile = ifc_tools.get_ifcfile(project)
layer = ifc_tools.api_run("layer.add_layer", ifcfile, Name=name)
try:
# IfcopenShell 0.8
layer = ifc_tools.api_run("layer.add_layer", ifcfile, name=name)
except:
# IfcopenShell 0.7
layer = ifc_tools.api_run("layer.add_layer", ifcfile, Name=name)
return get_layer(layer, project)


Expand Down
25 changes: 18 additions & 7 deletions src/Mod/BIM/nativeifc/ifc_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,23 @@ def set_material(material, obj):
if not container.OutList:
doc.removeObject(container.Name)
if material_element:
ifc_tools.api_run(
"material.assign_material",
ifcfile,
product=element,
type=material_element.is_a(),
material=material_element,
)
try:
# IfcOpenShell 0.8
ifc_tools.api_run(
"material.assign_material",
ifcfile,
products=[element],
type=material_element.is_a(),
material=material_element,
)
except:
# IfcOpenShell 0.7
ifc_tools.api_run(
"material.assign_material",
ifcfile,
product=element,
type=material_element.is_a(),
material=material_element,
)
if new:
show_material(obj)
Loading

0 comments on commit b8fddd1

Please sign in to comment.