1515from meshroom .common import BaseObject , DictModel , Slot , Signal , Property
1616from meshroom .core import Version
1717from meshroom .core .attribute import Attribute , ListAttribute , GroupAttribute
18- from meshroom .core .exception import StopGraphVisit , StopBranchVisit
18+ from meshroom .core .exception import GraphCompatibilityError , StopGraphVisit , StopBranchVisit
1919from meshroom .core .node import nodeFactory , Status , Node , CompatibilityNode
2020
2121# Replace default encoder to support Enums
@@ -214,6 +214,7 @@ def getFeaturesForVersion(fileVersion):
214214 def __init__ (self , name , parent = None ):
215215 super (Graph , self ).__init__ (parent )
216216 self .name = name
217+ self ._loading = False
217218 self ._updateEnabled = True
218219 self ._updateRequested = False
219220 self .dirtyTopology = False
@@ -246,6 +247,11 @@ def fileFeatures(self):
246247 """ Get loaded file supported features based on its version. """
247248 return Graph .IO .getFeaturesForVersion (self .header .get (Graph .IO .Keys .FileVersion , "0.0" ))
248249
250+ @property
251+ def isLoading (self ):
252+ """ Return True if the graph is currently being loaded. """
253+ return self ._loading
254+
249255 @Slot (str )
250256 def load (self , filepath , setupProjectFile = True , importProject = False , publishOutputs = False ):
251257 """
@@ -259,6 +265,13 @@ def load(self, filepath, setupProjectFile=True, importProject=False, publishOutp
259265 of opened.
260266 publishOutputs: True if "Publish" nodes from templates should not be ignored.
261267 """
268+ self ._loading = True
269+ try :
270+ self ._load (filepath , setupProjectFile , importProject , publishOutputs )
271+ finally :
272+ self ._loading = False
273+
274+ def _load (self , filepath , setupProjectFile , importProject , publishOutputs ):
262275 if not importProject :
263276 self .clear ()
264277 with open (filepath ) as jsonFile :
@@ -1633,11 +1646,27 @@ def setVerbose(self, v):
16331646 canComputeLeaves = Property (bool , lambda self : self ._canComputeLeaves , notify = canComputeLeavesChanged )
16341647
16351648
1636- def loadGraph (filepath ) :
1649+ def loadGraph (filepath , strictCompatibility : bool = False ) -> Graph :
16371650 """
1651+ Load a Graph from a Meshroom Graph (.mg) file.
1652+
1653+ Args:
1654+ filepath: The path to the Meshroom Graph file.
1655+ strictCompatibility: If True, raise a GraphCompatibilityError if the loaded Graph has node compatibility issues.
1656+
1657+ Returns:
1658+ Graph: The loaded Graph instance.
1659+
1660+ Raises:
1661+ GraphCompatibilityError: If the Graph has node compatibility issues and `strictCompatibility` is True.
16381662 """
16391663 graph = Graph ("" )
16401664 graph .load (filepath )
1665+
1666+ compatibilityIssues = len (graph .compatibilityNodes ) > 0
1667+ if compatibilityIssues and strictCompatibility :
1668+ raise GraphCompatibilityError (filepath , {n .name : str (n .issue ) for n in graph .compatibilityNodes })
1669+
16411670 graph .update ()
16421671 return graph
16431672
0 commit comments