Skip to content

Commit

Permalink
prevent omitting multiplicities when used for verbalisations (#274)
Browse files Browse the repository at this point in the history
 - close #274
  • Loading branch information
marcellussiegburg committed Nov 6, 2024
1 parent 0b5c955 commit 1bc0ae8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Modelling/CdOd/NameCdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import Modelling.CdOd.Types (
defaultCdDrawSettings,
isIllegal,
maxObjects,
omittedDefaultMultiplicityIsSet,
relationshipName,
renameClassesAndRelationships,
shuffleAnnotatedClassAndConnectionOrder,
Expand Down Expand Up @@ -284,6 +285,13 @@ checkNameCdErrorConfig :: NameCdErrorConfig -> Maybe String
checkNameCdErrorConfig NameCdErrorConfig {..}
| not (printNames drawSettings) && useNames
= Just "use names is only possible when printing names"
| not useNames
, Just x <- omittedDefaultMultiplicityIsSet (omittedDefaults drawSettings)
= Just [iii|
#{x} must be set to 'Nothing' when useNames is set to 'False'
because all multiplicities need to be printed for all relationships
in order to refer to them.
|]
| completelyInhabited objectProperties /= Just True
= Just "completelyInhabited needs to be set to 'Just True' for this task type"
| usesEveryRelationshipName objectProperties /= Just True
Expand Down Expand Up @@ -440,6 +448,13 @@ checkNameCdErrorInstance :: NameCdErrorInstance -> Maybe String
checkNameCdErrorInstance NameCdErrorInstance {..}
| not (printNames cdDrawSettings) && byName
= Just "by name is only possible when printing names"
| not byName
, Just x <- omittedDefaultMultiplicityIsSet (omittedDefaults cdDrawSettings)
= Just [iii|
#{x} must be set to 'Nothing' when byName is set to 'False'
because all multiplicities need to be printed for all relationships
in order to refer to them.
|]
| 1 /= length (filter fst $ M.elems errorReasons)
= Just [iii|
There needs to be exactly one error defined within errorReasons
Expand Down
15 changes: 15 additions & 0 deletions src/Modelling/CdOd/RepairCd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import Modelling.CdOd.Types (
defaultProperties,
fromClassDiagram,
maxObjects,
omittedDefaultMultiplicityIsSet,
relationshipName,
renameClassesAndRelationships,
shuffleAnyClassAndConnectionOrder,
Expand Down Expand Up @@ -287,6 +288,13 @@ checkRepairCdConfig :: RepairCdConfig -> Maybe String
checkRepairCdConfig RepairCdConfig {..}
| not (printNames drawSettings) && useNames
= Just "use names is only possible when printing names"
| not useNames
, Just x <- omittedDefaultMultiplicityIsSet (omittedDefaults drawSettings)
= Just [iii|
#{x} must be set to 'Nothing' when useNames is set to 'False'
because all multiplicities need to be printed for all relationships
in order to refer to them.
|]
| completelyInhabited objectProperties /= Just True
= Just "completelyInhabited needs to be set to 'Just True' for this task type"
| usesEveryRelationshipName objectProperties /= Just True
Expand Down Expand Up @@ -472,6 +480,13 @@ checkRepairCdInstance :: RepairCdInstance -> Maybe String
checkRepairCdInstance RepairCdInstance {..}
| not (printNames cdDrawSettings) && byName
= Just "by name is only possible when printing names"
| not byName
, Just x <- omittedDefaultMultiplicityIsSet (omittedDefaults cdDrawSettings)
= Just [iii|
#{x} must be set to 'Nothing' when byName is set to 'False'
because all multiplicities need to be printed for all relationships
in order to refer to them.
|]
| showExtendedFeedback && not showSolution
= Just [iii|
showExtendedFeedback leaks the correct solution
Expand Down
16 changes: 16 additions & 0 deletions src/Modelling/CdOd/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module Modelling.CdOd.Types (
maxObjects,
maxRelationships,
normaliseObjectDiagram,
omittedDefaultMultiplicityIsSet,
relationshipName,
renameClassesAndRelationships,
renameObjectsWithClassesAndLinksInOd,
Expand Down Expand Up @@ -836,6 +837,21 @@ defaultOmittedDefaultMultiplicities = OmittedDefaultMultiplicities {
compositionWholeOmittedDefaultMultiplicity = Just (1, Just 1)
}

{-|
Returns just the parameter name of 'OmittedDefaultMultiplicities'
which is set to 'Just' (or 'Nothing' if neither is).
-}
omittedDefaultMultiplicityIsSet :: OmittedDefaultMultiplicities -> Maybe String
omittedDefaultMultiplicityIsSet OmittedDefaultMultiplicities {..}
| isJust aggregationWholeOmittedDefaultMultiplicity
= Just "aggregationWholeOmittedDefaultMultiplicity"
| isJust associationOmittedDefaultMultiplicity
= Just "associationOmittedDefaultMultiplicity"
| isJust compositionWholeOmittedDefaultMultiplicity
= Just "compositionWholeOmittedDefaultMultiplicity"
| otherwise
= Nothing

checkOmittedDefaultMultiplicities :: OmittedDefaultMultiplicities -> Maybe String
checkOmittedDefaultMultiplicities OmittedDefaultMultiplicities {..} =
checkValidity aggregationWholeOmittedDefaultMultiplicity
Expand Down

0 comments on commit 1bc0ae8

Please sign in to comment.