https://www.slicer.org/w/index.php?title=Documentation/4.6/Developers/Logics&feed=atom&action=historyDocumentation/4.6/Developers/Logics - Revision history2024-03-28T22:36:10ZRevision history for this page on the wikiMediaWiki 1.33.0https://www.slicer.org/w/index.php?title=Documentation/4.6/Developers/Logics&diff=47802&oldid=prevUpdateBot: Nightly -> 4.62016-11-07T07:29:53Z<p>Nightly -> 4.6</p>
<p><b>New page</b></p><div><noinclude>{{documentation/versioncheck}}</noinclude><br />
<br />
== Overview ==<br />
<br />
A logic is a collection of "algorithms" that mainly process MRML nodes within a scene.<br />
<br />
Logics can be:<br />
* ''active'': observe the scene and nodes to react when receiving events are fired<br />
* ''passive'' (helper): collection of utility functions to simplify the handling of nodes (e.g. <code>AddArchetypeVolume</code> in Volumes logic, Application logic.)<br />
* a mix of both: not ideal.<br />
<br />
== Types of logics ==<br />
<br />
There are 5 types of logics within Slicer. Their role is usually dictated by their dependencies. The [http://slicer.org/doc/html/classvtkMRMLAbstractLogic__inherit__graph.png inheritance graph] can be useful to understand the relationship between each logic types.<br />
<!-- --------------------------------- --><br />
# '''MRML logics'''<br />
#: Location<br />
#:: ''Slicer/Libs/MRML/Logics''<br />
#: Dependencies<br />
#:: MRMLCore<br />
#:: no graphical dependency<br />
#:: no Slicer dendendency (can by used by other projects) <br />
#: Role<br />
#:: Contain the base classes for logics (<code>vtkMRMLAbstractLogic</code>, <code>vtkMRMLApplicationLogic</code>) and helper classes<br />
#:: MRML logics don't have access to the application, and so shouldn't contain any Slicer specific code.<br />
#: Examples:<br />
#::* factories: for MRML nodes (<code>vtkMRMLColorLogic</code> creates default <code>vtkMRMLColor*Nodes</code>)<br />
#::* helpers: <code>vtkMRMLModelHierarchyLogic</code><br />
<!-- --------------------------------- --><br />
# '''Slicer logics'''<br />
#: Location<br />
#:: ''Slicer/Base/Logics''<br />
#: Dependencies<br />
#:: MRMLLogic<br />
#: Role<br />
#:: Specialization of '''MRML Logics''' for the Slicer application.<br />
#: Examples:<br />
#::* <code>vtkSlicerColorLogic</code>: knows about the "application" default LUT IDs and custom application lut files.<br />
<!-- --------------------------------- --><br />
# '''Application logics'''<br />
#: Location<br />
#:: ''Slicer/Libs/MRML/Logics/vtkMRMLApplicationLogic.[h|cxx]'' and ''Slicer/Base/Logics/vtkSlicerApplicationLogic.[h|cxx]'' <br />
#: Dependencies<br />
#:: <code>vtkMRMLApplicationLogic</code> doesn't depend on Slicer however <code>vtkSlicerApplicationLogic</code> does.<br />
#: Role<br />
#:: Contains application specific information. <code>vtkMRMLApplicationLogic</code> is an abstract class that is specialized for the application using MRML (<code>vtkSlicerApplicationLogic</code> for Slicer) <br />
#:: <code>vtk[MRML/Slicer]ApplicationLogic</code> is NOT a singleton, however, it can be accessed by any logics (see <code>vtkMRMLAbstractLogic::SetApplicationLogic</code>) so it can be considered as such. It currently contains a list of nodes/logics, unique in the application. It is here for historic reasons (Slicer3), but it should not be seen as a placeholder for everything. Querying a module to get its logic should be preferred to access logics.<br />
<!-- --------------------------------- --><br />
# '''Module logics'''<br />
#: Location<br />
#:: ''Slicer/Modules/Loadable/XYZ/Logic/vtkSlicerXXXLogic''<br />
#: Dependencies<br />
#:: Slicer logics, XYZ nodes and optionally other module logics<br />
#: Role<br />
#:: A module logic is the module public API. While a module has typically (not necessarily) an associated widget/panel, no processing should be done within the widget, the widget is just the interface between the user and the logic/nodes. Modules can access other module logics (i.e. <code>qSlicerCoreApplication::moduleManager()->module("Volumes")->logic()</code>) if needed. There is maximum 1 module logic per module, however, it doesn't prevent the module logic to use helper logics (<code>vtkSlicerModelsLogic</code> can instantiate/use <code>vtkMRMLModelHierarchyLogic</code>).<br />
<!-- --------------------------------- --><br />
# '''[[Documentation/{{documentation/version}}/Developers/DisplayableManagers|Displayable managers]]'''<br />
#: Location<br />
#:: ''Slicer/Libs/MRML/DisplayableManager''<br />
#: Dependencies<br />
#:: MRMLLogic and vtkRendering<br />
#: Role<br />
#:: They are logics that focus on representing nodes in a VTK renderer and handling user interaction within the view.<br />
<br />
== Remarks ==<br />
<br />
A class (logic, widget...) should explicitly expose in its API the required logic(s) (e.g. <code>qMRMLColorPickerwidget::setColorLogic(vtkMRMLColorLogic*)</code>) instead of hiding the requirements by directly using the application logic (e.g. <code>this->GetApplicationLogic()->GetModelHierarchyLogic()</code> ).<br />
<br />
It is the role of the class instantiator to pass the required logics to the created class (e.g. the module plugin sets the module logic to the module widget). For module logics depending on other module logics, it is resolved in the <code>qSlicer*Module::setup()</code> function, <code>qSlicer*Modules</code> have access to all modules and their logics that way (i.e. <code>qSlicerCoreApplication::moduleManager()->module("Volumes")->logic()</code>).<br />
Exposing the requirements in the API instead of using singleton has the advantage of having a scope well defined and contained, the code becomes more modular and easier to unit test.</div>UpdateBot