From fd0c8c4ad28b859b7fa5d75b642cf9b64e67c6a3 Mon Sep 17 00:00:00 2001 From: Jan Bliznicenko Date: Sun, 30 Jun 2024 17:41:14 +0200 Subject: [PATCH] reworking tests - wip --- .../OPAbstractDiagramControllerTest.class.st | 13 + ...tionalRelationshipControllerTest.class.st} | 407 ++++++++++-------- .../OPAbstractElementControllerTest.class.st | 101 +++++ .../OPBaseControllerTest.class.st | 7 - .../OPBoundaryController.class.st | 3 +- .../OpenPonk-Core/OPControllerTest.class.st | 14 - .../OPDiagramController.class.st | 13 +- ...ss.st => OPDiagramControllerTest.class.st} | 184 ++++---- ...DirectionalRelationshipController.class.st | 34 +- ...ctionalRelationshipControllerTest.class.st | 39 ++ .../OPElementController.class.st | 14 + .../OPElementControllerTest.class.st | 207 +++++++-- .../OPTestAbstractModel.class.st | 5 +- .../OPTestEntityControllerTest.class.st | 216 ---------- .../OpenPonk-Spec/OPCanvasExporter.class.st | 120 ++++++ .../OPCanvasPDFExporter.class.st | 13 + .../OPCanvasPNGExporter.class.st | 56 +++ .../OpenPonk-Spec/OPCanvasPresenter.class.st | 117 ++--- .../OPCanvasSVGExporter.class.st | 13 + .../OPDiagramRemoveFigureCommand.class.st | 2 +- repository/OpenPonk-Spec/OPEditor.class.st | 25 +- .../OPExportImageDialog.class.st | 2 +- .../OPShowHideTabContentPresenter.class.st | 8 +- 23 files changed, 965 insertions(+), 648 deletions(-) create mode 100644 repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st rename repository/OpenPonk-Core/{OPTestRelationControllerTest.class.st => OPAbstractDirectionalRelationshipControllerTest.class.st} (51%) create mode 100644 repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st delete mode 100644 repository/OpenPonk-Core/OPControllerTest.class.st rename repository/OpenPonk-Core/{OPTestDiagramControllerTest.class.st => OPDiagramControllerTest.class.st} (74%) create mode 100644 repository/OpenPonk-Core/OPDirectionalRelationshipControllerTest.class.st delete mode 100644 repository/OpenPonk-Core/OPTestEntityControllerTest.class.st create mode 100644 repository/OpenPonk-Spec/OPCanvasExporter.class.st create mode 100644 repository/OpenPonk-Spec/OPCanvasPDFExporter.class.st create mode 100644 repository/OpenPonk-Spec/OPCanvasPNGExporter.class.st create mode 100644 repository/OpenPonk-Spec/OPCanvasSVGExporter.class.st diff --git a/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st b/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st new file mode 100644 index 00000000..7656305c --- /dev/null +++ b/repository/OpenPonk-Core/OPAbstractDiagramControllerTest.class.st @@ -0,0 +1,13 @@ +Class { + #name : 'OPAbstractDiagramControllerTest', + #superclass : 'OPBaseControllerTest', + #category : 'OpenPonk-Core-Controllers - Tests', + #package : 'OpenPonk-Core', + #tag : 'Controllers - Tests' +} + +{ #category : 'testing' } +OPAbstractDiagramControllerTest class >> isAbstract [ + + ^ self = OPAbstractDiagramControllerTest +] diff --git a/repository/OpenPonk-Core/OPTestRelationControllerTest.class.st b/repository/OpenPonk-Core/OPAbstractDirectionalRelationshipControllerTest.class.st similarity index 51% rename from repository/OpenPonk-Core/OPTestRelationControllerTest.class.st rename to repository/OpenPonk-Core/OPAbstractDirectionalRelationshipControllerTest.class.st index 5c58cc9e..9daebf6c 100644 --- a/repository/OpenPonk-Core/OPTestRelationControllerTest.class.st +++ b/repository/OpenPonk-Core/OPAbstractDirectionalRelationshipControllerTest.class.st @@ -1,169 +1,238 @@ -Class { - #name : 'OPTestRelationControllerTest', - #superclass : 'OPBaseControllerTest', - #category : 'OpenPonk-Core-Controllers - Tests', - #package : 'OpenPonk-Core', - #tag : 'Controllers - Tests' -} - -{ #category : 'accessing' } -OPTestRelationControllerTest >> controllerClass [ - ^ OPTestRelationController -] - -{ #category : 'accessing' } -OPTestRelationControllerTest >> diagramControllerClass [ - ^ OPTestDiagramController -] - -{ #category : 'accessing' } -OPTestRelationControllerTest >> diagramModelClass [ - ^ OPTestContainerModel -] - -{ #category : 'accessing' } -OPTestRelationControllerTest >> modelClass [ - ^ OPTestRelationModel -] - -{ #category : 'initialization' } -OPTestRelationControllerTest >> setUp [ - - | sourceController targetController | - super setUp. - sourceController := OPTestEntityController new. - sourceController diagramController: diagramController. - targetController := OPTestEntityController new. - targetController diagramController: diagramController. - controller source: sourceController. - controller target: targetController -] - -{ #category : 'tests - controllers' } -OPTestRelationControllerTest >> testAddController [ - controller model: model. - diagramController addController: controller. - self assert: (diagramController controllerForModel: model) equals: controller. - self assert: controller diagramController equals: diagramController -] - -{ #category : 'tests - construction' } -OPTestRelationControllerTest >> testCreateAndShow [ - - | subModel sourceController targetController | - sourceController := diagramController newControllerFor: - OPTestEntityModel new. - sourceController showWithoutDependentInDiagram: diagramController. - targetController := diagramController newControllerFor: - OPTestEntityModel new. - targetController showWithoutDependentInDiagram: diagramController. - controller source: sourceController. - controller target: targetController. - controller - createModelIn: diagramController model - andShowInDiagram: diagramController. - self assert: diagramController model entities isNotEmpty. - subModel := diagramController model entities first. - self assert: (diagramController controllers includes: controller). - self assert: - (diagramController canvas lines includes: controller roassalShape) -] - -{ #category : 'tests - construction' } -OPTestRelationControllerTest >> testCreateModel [ - | sourceController targetController | - sourceController := diagramController - newControllerFor: OPTestEntityModel new. - sourceController showWithoutDependentInDiagram: diagramController. - targetController := diagramController - newControllerFor: OPTestEntityModel new. - targetController showWithoutDependentInDiagram: diagramController. - controller source: sourceController. - controller target: targetController. - controller createModelIn: diagramController model. - self assert: controller model isNotNil. - self assert: controller model source equals: sourceController model. - self assert: controller model target equals: targetController model -] - -{ #category : 'tests - controllers' } -OPTestRelationControllerTest >> testFigureForModel [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: (diagramController roassalShapeForModel: model) - equals: controller roassalShape -] - -{ #category : 'tests - construction' } -OPTestRelationControllerTest >> testFigureWasRendered [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self assert: - (diagramController canvas lines includes: controller roassalShape) -] - -{ #category : 'tests - controllers' } -OPTestRelationControllerTest >> testModelForFigure [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: - (diagramController modelForFigure: controller roassalShape) - equals: model -] - -{ #category : 'tests - controllers' } -OPTestRelationControllerTest >> testNewController [ - controller := diagramController newControllerFor: model. - self assert: controller class equals: self controllerClass -] - -{ #category : 'tests - ui interaction' } -OPTestRelationControllerTest >> testOpenInForm [ - - | form | - controller model: model. - form := OPDynamicForm new. - diagramController stub form willReturn: form. - self assert: form layout children isEmpty. - diagramController openInForm: controller. - self assert: form layout children isNotEmpty -] - -{ #category : 'tests - destruction' } -OPTestRelationControllerTest >> testRemoveController [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - controller removeController. - self - should: [ diagramController controllerForModel: model ] - raise: NotFound. - self assert: diagramController canvas nodes asArray equals: { } -] - -{ #category : 'tests - destruction' } -OPTestRelationControllerTest >> testRemoveFigureAndModel [ - - diagramController model entities add: model. - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - diagramController removeFromCanvas: controller roassalShape. - self assert: diagramController controllers asArray equals: { }. - self assert: diagramController model entities asArray equals: { } -] - -{ #category : 'tests - construction' } -OPTestRelationControllerTest >> testShowInDiagram [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: (diagramController controllerForRoassalShape: - controller roassalShape) - equals: controller -] +Class { + #name : 'OPAbstractDirectionalRelationshipControllerTest', + #superclass : 'OPAbstractElementControllerTest', + #instVars : [ + 'sourceModel', + 'targetModel' + ], + #category : 'OpenPonk-Core-Controllers - Tests', + #package : 'OpenPonk-Core', + #tag : 'Controllers - Tests' +} + +{ #category : 'testing' } +OPAbstractDirectionalRelationshipControllerTest class >> isAbstract [ + + ^ self = OPAbstractDirectionalRelationshipControllerTest +] + +{ #category : 'running' } +OPAbstractDirectionalRelationshipControllerTest >> addModelToDiagramModel [ + + self addToDiagramModel: model +] + +{ #category : 'running' } +OPAbstractDirectionalRelationshipControllerTest >> addSourceToDiagramModel [ + + self addToDiagramModel: sourceModel +] + +{ #category : 'running' } +OPAbstractDirectionalRelationshipControllerTest >> addTargetToDiagramModel [ + + self addToDiagramModel: targetModel +] + +{ #category : 'running' } +OPAbstractDirectionalRelationshipControllerTest >> addToDiagramModel: aModel [ + + diagramController model add: aModel +] + +{ #category : 'initialization' } +OPAbstractDirectionalRelationshipControllerTest >> assignModelSource [ + + model source: sourceModel +] + +{ #category : 'initialization' } +OPAbstractDirectionalRelationshipControllerTest >> assignModelTarget [ + + model target: targetModel +] + +{ #category : 'accessing' } +OPAbstractDirectionalRelationshipControllerTest >> creationTargetControllerClass [ + + ^ self sourceControllerClass +] + +{ #category : 'accessing' } +OPAbstractDirectionalRelationshipControllerTest >> creationTargetModelClass [ + + ^ self sourceModelClass +] + +{ #category : 'running' } +OPAbstractDirectionalRelationshipControllerTest >> setUp [ + + super setUp. + sourceModel := self sourceModelClass new. + targetModel := self targetModelClass new. + self assignModelSource. + self assignModelTarget. + self addSourceToDiagramModel. + self addTargetToDiagramModel. + self addModelToDiagramModel +] + +{ #category : 'as yet unclassified' } +OPAbstractDirectionalRelationshipControllerTest >> sourceControllerClass [ + + ^ self subclassResponsibility +] + +{ #category : 'accessing' } +OPAbstractDirectionalRelationshipControllerTest >> sourceModelClass [ + + ^ self subclassResponsibility +] + +{ #category : 'as yet unclassified' } +OPAbstractDirectionalRelationshipControllerTest >> targetControllerClass [ + + ^ self sourceControllerClass +] + +{ #category : 'accessing' } +OPAbstractDirectionalRelationshipControllerTest >> targetModelClass [ + + ^ self sourceModelClass +] + +{ #category : 'tests - controllers' } +OPAbstractDirectionalRelationshipControllerTest >> testAddController [ + controller model: model. + diagramController addController: controller. + self assert: (diagramController controllerForModel: model) equals: controller. + self assert: controller diagramController equals: diagramController +] + +{ #category : 'tests - construction' } +OPAbstractDirectionalRelationshipControllerTest >> testCreateAndShow [ + + | subModel sourceController targetController | + sourceController := diagramController newControllerFor: + OPTestEntityModel new. + sourceController showWithoutDependentInDiagram: diagramController. + targetController := diagramController newControllerFor: + OPTestEntityModel new. + targetController showWithoutDependentInDiagram: diagramController. + controller source: sourceController. + controller target: targetController. + controller + createModelIn: diagramController model + andShowInDiagram: diagramController. + self assert: diagramController model entities isNotEmpty. + subModel := diagramController model entities first. + self assert: (diagramController controllers includes: controller). + self assert: + (diagramController canvas lines includes: controller roassalShape) +] + +{ #category : 'tests - construction' } +OPAbstractDirectionalRelationshipControllerTest >> testCreateModel [ + | sourceController targetController | + sourceController := diagramController + newControllerFor: OPTestEntityModel new. + sourceController showWithoutDependentInDiagram: diagramController. + targetController := diagramController + newControllerFor: OPTestEntityModel new. + targetController showWithoutDependentInDiagram: diagramController. + controller source: sourceController. + controller target: targetController. + controller createModelIn: diagramController model. + self assert: controller model isNotNil. + self assert: controller model source equals: sourceController model. + self assert: controller model target equals: targetController model +] + +{ #category : 'tests - controllers' } +OPAbstractDirectionalRelationshipControllerTest >> testFigureForModel [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self + assert: (diagramController roassalShapeForModel: model) + equals: controller roassalShape +] + +{ #category : 'tests - construction' } +OPAbstractDirectionalRelationshipControllerTest >> testFigureWasRendered [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self assert: + (diagramController canvas lines includes: controller roassalShape) +] + +{ #category : 'tests - controllers' } +OPAbstractDirectionalRelationshipControllerTest >> testModelForFigure [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self + assert: + (diagramController modelForFigure: controller roassalShape) + equals: model +] + +{ #category : 'tests - controllers' } +OPAbstractDirectionalRelationshipControllerTest >> testNewController [ + controller := diagramController newControllerFor: model. + self assert: controller class equals: self controllerClass +] + +{ #category : 'tests - ui interaction' } +OPAbstractDirectionalRelationshipControllerTest >> testOpenInForm [ + + | form | + controller model: model. + form := OPDynamicForm new. + diagramController stub form willReturn: form. + self assert: form layout children isEmpty. + diagramController openInForm: controller. + self assert: form layout children isNotEmpty +] + +{ #category : 'tests - destruction' } +OPAbstractDirectionalRelationshipControllerTest >> testRemoveController [ + + controller model: model. + self assert: diagramController canvas shapes size equals: 0. + controller showWithoutDependentInDiagram: diagramController. + + self assert: diagramController canvas shapes size equals: 3. + controller removeController. + self + should: [ diagramController controllerForModel: model ] + raise: NotFound. + self assert: diagramController canvas shapes size equals: 2 +] + +{ #category : 'tests - destruction' } +OPAbstractDirectionalRelationshipControllerTest >> testRemoveFigureAndModel [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self assert: diagramController model entities size equals: 3. + self assert: diagramController canvas shapes size equals: 3. + diagramController removeModelOfRoassalShape: controller roassalShape. + self assert: diagramController controllers size equals: 2. + + self assert: diagramController model entities size equals: 2. + self assert: diagramController canvas shapes size equals: 2 +] + +{ #category : 'tests - construction' } +OPAbstractDirectionalRelationshipControllerTest >> testShowInDiagram [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self + assert: + (diagramController controllerForRoassalShape: + controller roassalShape) + equals: controller +] diff --git a/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st b/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st new file mode 100644 index 00000000..3615944e --- /dev/null +++ b/repository/OpenPonk-Core/OPAbstractElementControllerTest.class.st @@ -0,0 +1,101 @@ +Class { + #name : 'OPAbstractElementControllerTest', + #superclass : 'OPBaseControllerTest', + #instVars : [ + 'creationTargetController' + ], + #category : 'OpenPonk-Core-Controllers - Tests', + #package : 'OpenPonk-Core', + #tag : 'Controllers - Tests' +} + +{ #category : 'testing' } +OPAbstractElementControllerTest class >> isAbstract [ + + ^ self = OPAbstractElementControllerTest +] + +{ #category : 'accessing' } +OPAbstractElementControllerTest >> creationTargetControllerClass [ + ^ self subclassResponsibility +] + +{ #category : 'accessing' } +OPAbstractElementControllerTest >> creationTargetModelClass [ + ^ self subclassResponsibility +] + +{ #category : 'running' } +OPAbstractElementControllerTest >> setUp [ + super setUp. + self setUpCreationTarget +] + +{ #category : 'accessing' } +OPAbstractElementControllerTest >> setUpCreationTarget [ + creationTargetController := self creationTargetControllerClass new. + creationTargetController diagramController: diagramController. + creationTargetController createModelIn: diagramController model +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testClassSideModelClass [ + + self assert: self controllerClass modelClass equals: self modelClass +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testCreateController [ + self assert: controller class equals: self controllerClass +] + +{ #category : 'tests - creation' } +OPAbstractElementControllerTest >> testCreateDiagramElement [ + + self diagramControllerClass = self controllerClass ifTrue: [ + self skip ]. + self class = OPAbstractElementControllerTest ifTrue: [ self skip ]. + + controller model: model. + controller diagramController: diagramController. + controller ensureShownDependenciesInDiagram: diagramController. + controller createDiagramElement. + self + assert: controller diagramElement class + equals: self diagramElementClass +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testDescriptionName [ + | diagramElement | + model := Mock new. + model stub name willReturn: 'bravo'. + diagramElement := Mock new. + controller model: model. + controller diagramElement: diagramElement. + self stubRefresh. + controller descriptionName accessor write: 'charlie' to: controller. + model should receive name: 'charlie'. + self assert: (controller descriptionName accessor read: controller) equals: 'bravo'. + diagramElement should receive modelChanged +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testIsSupported [ + + self class = OPAbstractElementControllerTest ifTrue: [ ^ self ]. + super testIsSupported +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testModelClass [ + self assert: controller modelClass equals: self modelClass +] + +{ #category : 'tests' } +OPAbstractElementControllerTest >> testModelIsSubscribedTo [ + controller := OPController new. + model := self modelClass new. + controller model: model. + self assert: model announcer subscriptions subscriptions anyOne subscriber equals: controller +] diff --git a/repository/OpenPonk-Core/OPBaseControllerTest.class.st b/repository/OpenPonk-Core/OPBaseControllerTest.class.st index efbb083a..8014e11a 100644 --- a/repository/OpenPonk-Core/OPBaseControllerTest.class.st +++ b/repository/OpenPonk-Core/OPBaseControllerTest.class.st @@ -80,10 +80,3 @@ OPBaseControllerTest >> testIsSupported [ ifTrue: [ ^ self ]. self assert: (diagramController hasSupportForModel: model) ] - -{ #category : 'tests' } -OPBaseControllerTest >> testModelClass [ - self diagramControllerClass = self controllerClass - ifTrue: [ ^ self ]. - self assert: controller modelClass equals: self modelClass -] diff --git a/repository/OpenPonk-Core/OPBoundaryController.class.st b/repository/OpenPonk-Core/OPBoundaryController.class.st index b0ca78e0..b34119d9 100644 --- a/repository/OpenPonk-Core/OPBoundaryController.class.st +++ b/repository/OpenPonk-Core/OPBoundaryController.class.st @@ -46,6 +46,7 @@ OPBoundaryController >> renderDiagramElement [ super renderDiagramElement. diagramElement announcer when: OPElementTextAttributeChanged - do: [ diagramElement updateRenderFromSelf ]. + do: [ diagramElement updateRenderFromSelf ] + for: self. ^ self roassalShape ] diff --git a/repository/OpenPonk-Core/OPControllerTest.class.st b/repository/OpenPonk-Core/OPControllerTest.class.st deleted file mode 100644 index c3c0f25c..00000000 --- a/repository/OpenPonk-Core/OPControllerTest.class.st +++ /dev/null @@ -1,14 +0,0 @@ -Class { - #name : 'OPControllerTest', - #superclass : 'OPElementControllerTest', - #category : 'OpenPonk-Core-Controllers - Tests', - #package : 'OpenPonk-Core', - #tag : 'Controllers - Tests' -} - -{ #category : 'testing' } -OPControllerTest class >> isDeprecated [ - "Use OPElementControllerTest" - - ^ true -] diff --git a/repository/OpenPonk-Core/OPDiagramController.class.st b/repository/OpenPonk-Core/OPDiagramController.class.st index a6dfa6b9..292fc85d 100644 --- a/repository/OpenPonk-Core/OPDiagramController.class.st +++ b/repository/OpenPonk-Core/OPDiagramController.class.st @@ -613,8 +613,11 @@ OPDiagramController >> removeControllerOf: aModelElement [ { #category : 'destruction' } OPDiagramController >> removeFromCanvas: aFigure [ - aFigure ifNil: [ ^ self ]. - (self controllerForRoassalShape: aFigure) removeControllerAndModel + + self + deprecated: 'use removeModelOfRoassalShape: instead' + transformWith: '`@rcv removeFromCanvas: `@arg' + -> '`@rcv removeModelOfRoassalShape: `@arg' ] { #category : 'deprecated' } @@ -643,6 +646,12 @@ OPDiagramController >> removeModelElement: aModelElement [ (self controllerForModel: aModelElement) removeModel ] +{ #category : 'destruction' } +OPDiagramController >> removeModelOfRoassalShape: aFigure [ + aFigure ifNil: [ ^ self ]. + (self controllerForRoassalShape: aFigure) removeControllerAndModel +] + { #category : 'accessing' } OPDiagramController >> rendered: aController [ diff --git a/repository/OpenPonk-Core/OPTestDiagramControllerTest.class.st b/repository/OpenPonk-Core/OPDiagramControllerTest.class.st similarity index 74% rename from repository/OpenPonk-Core/OPTestDiagramControllerTest.class.st rename to repository/OpenPonk-Core/OPDiagramControllerTest.class.st index 8305ccb8..f7576200 100644 --- a/repository/OpenPonk-Core/OPTestDiagramControllerTest.class.st +++ b/repository/OpenPonk-Core/OPDiagramControllerTest.class.st @@ -1,92 +1,92 @@ -Class { - #name : 'OPTestDiagramControllerTest', - #superclass : 'OPBaseControllerTest', - #category : 'OpenPonk-Core-Controllers - Tests', - #package : 'OpenPonk-Core', - #tag : 'Controllers - Tests' -} - -{ #category : 'accessing' } -OPTestDiagramControllerTest >> controllerClass [ - ^ OPTestDiagramController -] - -{ #category : 'accessing' } -OPTestDiagramControllerTest >> diagramControllerClass [ - ^ OPTestDiagramController -] - -{ #category : 'accessing' } -OPTestDiagramControllerTest >> diagramModelClass [ - ^ OPTestContainerModel -] - -{ #category : 'accessing' } -OPTestDiagramControllerTest >> modelClass [ - ^ OPTestContainerModel -] - -{ #category : 'tests - connecting' } -OPTestDiagramControllerTest >> testAddAsTargetForEntity [ - | entityController | - entityController := diagramController newControllerFor: OPTestEntityModel new. - diagramController addAsTargetFor: entityController. - self assert: diagramController model entities asArray equals: {entityController model}. - self assert: diagramController controllers asArray equals: {entityController} -] - -{ #category : 'tests - ui interaction' } -OPTestDiagramControllerTest >> testAttachEditor [ - | editor workbench plugin | - plugin := OPPlugin new. - plugin stub layouterClass willReturn: OPLayouter. - editor := OPEditor on: plugin. - workbench := OPWorkbench new. - editor stub workbench willReturn: workbench. - diagramController editor: editor. - self assert: diagramController form isNotNil -] - -{ #category : 'tests - connecting' } -OPTestDiagramControllerTest >> testCanBeTargetForEntity [ - self - assert: - (diagramController - canBeTargetFor: (diagramController newControllerFor: OPTestEntityModel new)) -] - -{ #category : 'tests - ui interaction' } -OPTestDiagramControllerTest >> testInitializePalette [ - | palette | - palette := OPPalette new. - self assert: palette items size = 2. - diagramController initializePalette: palette. - self assert: palette items size = 3 -] - -{ #category : 'tests' } -OPTestDiagramControllerTest >> testModelClass [ - | plugin pluginRegistry | - plugin := OPPlugin new. - plugin stub modelClass willReturn: self diagramModelClass. - plugin stub diagramControllerClass willReturn: self diagramControllerClass. - pluginRegistry := OPPluginRegistry new add: plugin. - [ OPPluginRegistry setDefault: pluginRegistry. - self assert: diagramController modelClass equals: self diagramModelClass ] - ensure: [ OPPluginRegistry setDefault: nil ] -] - -{ #category : 'tests - construction' } -OPTestDiagramControllerTest >> testShowModelInDiagram [ - | entity | - entity := OPTestEntityModel new. - diagramController showWithoutDependentInDiagramModel: entity -] - -{ #category : 'tests - construction' } -OPTestDiagramControllerTest >> testShowModelInDiagramAttachesController [ - | entity | - entity := OPTestEntityModel new. - diagramController showWithoutDependentInDiagramModel: entity. - self shouldnt: (diagramController controllerForModel: entity) raise: NotFound -] +Class { + #name : 'OPDiagramControllerTest', + #superclass : 'OPAbstractDiagramControllerTest', + #category : 'OpenPonk-Core-Controllers - Tests', + #package : 'OpenPonk-Core', + #tag : 'Controllers - Tests' +} + +{ #category : 'accessing' } +OPDiagramControllerTest >> controllerClass [ + ^ OPTestDiagramController +] + +{ #category : 'accessing' } +OPDiagramControllerTest >> diagramControllerClass [ + ^ OPTestDiagramController +] + +{ #category : 'accessing' } +OPDiagramControllerTest >> diagramModelClass [ + ^ OPTestContainerModel +] + +{ #category : 'accessing' } +OPDiagramControllerTest >> modelClass [ + ^ OPTestContainerModel +] + +{ #category : 'tests - connecting' } +OPDiagramControllerTest >> testAddAsTargetForEntity [ + | entityController | + entityController := diagramController newControllerFor: OPTestEntityModel new. + diagramController addAsTargetFor: entityController. + self assert: diagramController model entities asArray equals: {entityController model}. + self assert: diagramController controllers asArray equals: {entityController} +] + +{ #category : 'tests - ui interaction' } +OPDiagramControllerTest >> testAttachEditor [ + | editor workbench plugin | + plugin := OPPlugin new. + plugin stub layouterClass willReturn: OPLayouter. + editor := OPEditor on: plugin. + workbench := OPWorkbench new. + editor stub workbench willReturn: workbench. + diagramController editor: editor. + self assert: diagramController form isNotNil +] + +{ #category : 'tests - connecting' } +OPDiagramControllerTest >> testCanBeTargetForEntity [ + self + assert: + (diagramController + canBeTargetFor: (diagramController newControllerFor: OPTestEntityModel new)) +] + +{ #category : 'tests - ui interaction' } +OPDiagramControllerTest >> testInitializePalette [ + | palette | + palette := OPPalette new. + self assert: palette items size = 2. + diagramController initializePalette: palette. + self assert: palette items size = 3 +] + +{ #category : 'tests' } +OPDiagramControllerTest >> testModelClass [ + | plugin pluginRegistry | + plugin := OPPlugin new. + plugin stub modelClass willReturn: self diagramModelClass. + plugin stub diagramControllerClass willReturn: self diagramControllerClass. + pluginRegistry := OPPluginRegistry new add: plugin. + [ OPPluginRegistry setDefault: pluginRegistry. + self assert: diagramController modelClass equals: self diagramModelClass ] + ensure: [ OPPluginRegistry setDefault: nil ] +] + +{ #category : 'tests - construction' } +OPDiagramControllerTest >> testShowModelInDiagram [ + | entity | + entity := OPTestEntityModel new. + diagramController showWithoutDependentInDiagramModel: entity +] + +{ #category : 'tests - construction' } +OPDiagramControllerTest >> testShowModelInDiagramAttachesController [ + | entity | + entity := OPTestEntityModel new. + diagramController showWithoutDependentInDiagramModel: entity. + self shouldnt: (diagramController controllerForModel: entity) raise: NotFound +] diff --git a/repository/OpenPonk-Core/OPDirectionalRelationshipController.class.st b/repository/OpenPonk-Core/OPDirectionalRelationshipController.class.st index 8a60b42a..8f8169a9 100644 --- a/repository/OpenPonk-Core/OPDirectionalRelationshipController.class.st +++ b/repository/OpenPonk-Core/OPDirectionalRelationshipController.class.st @@ -41,6 +41,18 @@ OPDirectionalRelationshipController >> createModelIn: aParentModel [ ^ self model ] +{ #category : 'construction' } +OPDirectionalRelationshipController >> dependingOnElements [ + + ^ super dependingOnElements , (Set + with: (self model + ifNil: [ self source model ] + ifNotNil: [ self modelSource ]) + with: (self model + ifNil: [ self target model ] + ifNotNil: [ self modelTarget ])) +] + { #category : 'hooks' } OPDirectionalRelationshipController >> edgeBuilder [ @@ -48,6 +60,14 @@ OPDirectionalRelationshipController >> edgeBuilder [ 'Depracated without replacement - use Roassal directly or define own figures' ] +{ #category : 'construction' } +OPDirectionalRelationshipController >> ensureShownDependenciesInDiagram: aDiagramController [ + + self ensureSourceIn: aDiagramController. + self ensureTargetIn: aDiagramController. + super ensureShownDependenciesInDiagram: aDiagramController +] + { #category : 'accessing' } OPDirectionalRelationshipController >> ensureSourceIn: aDiagramController [ @@ -84,19 +104,10 @@ OPDirectionalRelationshipController >> renderSimplified [ diagramElement := self diagramElementClass renderSimplifiedForController: self. ] -{ #category : 'construction' } -OPDirectionalRelationshipController >> showWithoutDependentInDiagram: aDiagramController [ - - self ensureSourceIn: aDiagramController. - self ensureTargetIn: aDiagramController. - ^ super showWithoutDependentInDiagram: aDiagramController -] - { #category : 'accessing' } OPDirectionalRelationshipController >> source [ - ^ self ensureSourceIn: - (self diagramController ifNil: [ self target diagramController ]) + ^ source ] { #category : 'accessing' } @@ -108,8 +119,7 @@ OPDirectionalRelationshipController >> source: aSourceController [ { #category : 'accessing' } OPDirectionalRelationshipController >> target [ - ^ self ensureTargetIn: - (self diagramController ifNil: [ self source diagramController ]) + ^ target ] { #category : 'accessing' } diff --git a/repository/OpenPonk-Core/OPDirectionalRelationshipControllerTest.class.st b/repository/OpenPonk-Core/OPDirectionalRelationshipControllerTest.class.st new file mode 100644 index 00000000..ec8f7c0d --- /dev/null +++ b/repository/OpenPonk-Core/OPDirectionalRelationshipControllerTest.class.st @@ -0,0 +1,39 @@ +Class { + #name : 'OPDirectionalRelationshipControllerTest', + #superclass : 'OPAbstractDirectionalRelationshipControllerTest', + #category : 'OpenPonk-Core-Controllers - Tests', + #package : 'OpenPonk-Core', + #tag : 'Controllers - Tests' +} + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> controllerClass [ + ^ OPTestRelationController +] + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> diagramControllerClass [ + ^ OPTestDiagramController +] + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> diagramModelClass [ + ^ OPTestContainerModel +] + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> modelClass [ + ^ OPTestRelationModel +] + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> sourceControllerClass [ + + ^ OPTestEntityController +] + +{ #category : 'accessing' } +OPDirectionalRelationshipControllerTest >> sourceModelClass [ + + ^ OPTestEntityModel +] diff --git a/repository/OpenPonk-Core/OPElementController.class.st b/repository/OpenPonk-Core/OPElementController.class.st index 6c70301b..e3c18300 100644 --- a/repository/OpenPonk-Core/OPElementController.class.st +++ b/repository/OpenPonk-Core/OPElementController.class.st @@ -77,6 +77,12 @@ OPElementController >> createModelIn: aParentModel andShowInDiagram: aDiagramCon self showWithoutDependentInDiagram: aDiagramController ] +{ #category : 'construction' } +OPElementController >> dependingOnElements [ + + ^ Set empty +] + { #category : 'construction' } OPElementController >> diagramElementClass [ @@ -98,6 +104,13 @@ OPElementController >> ensureDiagramElement [ ^ diagramElement ] +{ #category : 'construction' } +OPElementController >> ensureShownDependenciesInDiagram: aDiagramController [ + + ^ self dependingOnElements do: [ :each | + aDiagramController showWithoutDependentInDiagramModel: each ] +] + { #category : 'figures' } OPElementController >> figure: aFigure [ @@ -196,6 +209,7 @@ OPElementController >> showInDiagram: aDiagramController [ { #category : 'construction' } OPElementController >> showWithoutDependentInDiagram: aDiagramController [ + self ensureShownDependenciesInDiagram: aDiagramController. aDiagramController addController: self. self ensureDiagramElement. self renderDiagramElement diff --git a/repository/OpenPonk-Core/OPElementControllerTest.class.st b/repository/OpenPonk-Core/OPElementControllerTest.class.st index 631f4412..abd837d5 100644 --- a/repository/OpenPonk-Core/OPElementControllerTest.class.st +++ b/repository/OpenPonk-Core/OPElementControllerTest.class.st @@ -1,6 +1,6 @@ Class { #name : 'OPElementControllerTest', - #superclass : 'OPBaseControllerTest', + #superclass : 'OPAbstractElementControllerTest', #category : 'OpenPonk-Core-Controllers - Tests', #package : 'OpenPonk-Core', #tag : 'Controllers - Tests' @@ -18,7 +18,6 @@ OPElementControllerTest >> diagramControllerClass [ { #category : 'accessing' } OPElementControllerTest >> diagramModelClass [ - ^ OPTestContainerModel ] @@ -27,53 +26,191 @@ OPElementControllerTest >> modelClass [ ^ OPTestEntityModel ] -{ #category : 'tests' } -OPElementControllerTest >> testClassSideModelClass [ +{ #category : 'tests - connecting' } +OPElementControllerTest >> testAddAsSourceAndTargetForRelation [ + | sourceModel targetModel relationController relationModel | + sourceModel := self newModel. + targetModel := self newModel. + diagramController model + add: sourceModel; + add: targetModel. + diagramController showAllElements. + relationController := diagramController + newControllerFor: OPTestRelationModel new. + (diagramController controllerForModel: sourceModel) + addAsSourceFor: relationController. + (diagramController controllerForModel: targetModel) + addAsTargetFor: relationController. + relationModel := relationController model. + self + assert: (diagramController controllers includes: relationController). + self + assert: diagramController model entities asArray + equals: (Array with: sourceModel with: targetModel with: relationModel). + self assert: relationModel source equals: sourceModel. + self assert: relationModel target equals: targetModel +] + +{ #category : 'tests - connecting' } +OPElementControllerTest >> testAddAsSourceAndTargetForRelationToSelf [ + | relationController relationModel | + controller model: model. + diagramController model add: model. + controller showWithoutDependentInDiagram: diagramController. + relationController := diagramController + newControllerFor: OPTestRelationModel new. + controller addAsSourceFor: relationController. + controller addAsTargetFor: relationController. + relationModel := relationController model. + self + assertCollection: diagramController controllers asSet + equals: + {controller. + relationController} asSet. + self + assertCollection: diagramController model entities asSet + equals: + {model. + relationModel} asSet. + self assert: relationModel source equals: model. + self assert: relationModel target equals: model +] + +{ #category : 'tests - connecting' } +OPElementControllerTest >> testAddAsSourceForRelation [ + | relationController | + relationController := diagramController + newControllerFor: OPTestRelationModel new. + controller addAsSourceFor: relationController. + self assert: diagramController controllers asArray equals: {}. + self assert: relationController source equals: controller +] + +{ #category : 'tests - controllers' } +OPElementControllerTest >> testAddController [ + controller model: model. + diagramController addController: controller. + self assert: (diagramController controllerForModel: model) equals: controller. + self assert: controller diagramController equals: diagramController +] - self assert: self controllerClass modelClass equals: self modelClass +{ #category : 'tests - connecting' } +OPElementControllerTest >> testCanBeSourceForRelation [ + self + assert: + (controller + canBeSourceFor: (diagramController newControllerFor: OPTestRelationModel new)) ] -{ #category : 'tests - creation' } -OPElementControllerTest >> testCreateDiagramElement [ +{ #category : 'tests - connecting' } +OPElementControllerTest >> testCanBeTargetForRelation [ + self + assert: + (controller + canBeTargetFor: (diagramController newControllerFor: OPTestRelationModel new)) +] - self diagramControllerClass = self controllerClass ifTrue: [ - self skip ]. - self class = OPElementControllerTest ifTrue: [ self skip ]. +{ #category : 'tests - construction' } +OPElementControllerTest >> testCreateAndShow [ + + | subModel | + controller + createModelIn: diagramController model + andShowInDiagram: diagramController. + self assert: diagramController model entities isNotEmpty. + subModel := diagramController model entities first. + self + assert: diagramController controllers asArray + equals: { controller }. + self assert: + (diagramController canvas nodes includes: controller roassalShape) +] + +{ #category : 'tests - construction' } +OPElementControllerTest >> testCreateModel [ + controller createModelIn: diagramController model. + self assert: controller model isNotNil. + self assert: diagramController model entities asArray equals: {controller model} +] + +{ #category : 'tests - controllers' } +OPElementControllerTest >> testFigureForModel [ controller model: model. - controller diagramController: diagramController. - controller createDiagramElement. + controller showWithoutDependentInDiagram: diagramController. self - assert: controller diagramElement class - equals: self diagramElementClass + assert: (diagramController roassalShapeForModel: model) + equals: controller roassalShape ] -{ #category : 'tests' } -OPElementControllerTest >> testDescriptionName [ - | diagramElement | - model := Mock new. - model stub name willReturn: 'bravo'. - diagramElement := Mock new. +{ #category : 'tests - construction' } +OPElementControllerTest >> testFigureWasRendered [ + controller model: model. - controller diagramElement: diagramElement. - self stubRefresh. - controller descriptionName accessor write: 'charlie' to: controller. - model should receive name: 'charlie'. - self assert: (controller descriptionName accessor read: controller) equals: 'bravo'. - diagramElement should receive modelChanged + controller showWithoutDependentInDiagram: diagramController. + self assert: + (diagramController canvas nodes includes: controller roassalShape) ] -{ #category : 'tests' } -OPElementControllerTest >> testIsSupported [ +{ #category : 'tests - controllers' } +OPElementControllerTest >> testModelForFigure [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self + assert: + (diagramController modelForFigure: controller roassalShape) + equals: model +] - self class = OPElementControllerTest ifTrue: [ ^ self ]. - super testIsSupported +{ #category : 'tests - controllers' } +OPElementControllerTest >> testNewController [ + controller := diagramController newControllerFor: model. + self assert: controller class equals: self controllerClass ] -{ #category : 'tests' } -OPElementControllerTest >> testModelIsSubscribedTo [ - controller := OPController new. - model := self modelClass new. +{ #category : 'tests - ui interaction' } +OPElementControllerTest >> testOpenInForm [ + + | form | + controller model: model. + form := OPDynamicForm new. + diagramController stub form willReturn: form. + self assert: form layout children isEmpty. + diagramController openInForm: controller. + self assert: form layout children isNotEmpty +] + +{ #category : 'tests - destruction' } +OPElementControllerTest >> testRemoveController [ + controller model: model. - self assert: model announcer subscriptions subscriptions anyOne subscriber equals: controller + controller showWithoutDependentInDiagram: diagramController. + controller removeController. + self + should: [ diagramController controllerForModel: model ] + raise: NotFound. + self assert: diagramController canvas nodes asArray equals: { } +] + +{ #category : 'tests - destruction' } +OPElementControllerTest >> testRemoveFigureAndModel [ + + diagramController model entities add: model. + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + diagramController removeModelOfRoassalShape: controller roassalShape. + self assert: diagramController controllers asArray equals: { }. + self assert: diagramController model entities asArray equals: { } +] + +{ #category : 'tests - construction' } +OPElementControllerTest >> testShowInDiagram [ + + controller model: model. + controller showWithoutDependentInDiagram: diagramController. + self + assert: (diagramController controllerForRoassalShape: + controller roassalShape) + equals: controller ] diff --git a/repository/OpenPonk-Core/OPTestAbstractModel.class.st b/repository/OpenPonk-Core/OPTestAbstractModel.class.st index ec3cfb65..d3308a20 100644 --- a/repository/OpenPonk-Core/OPTestAbstractModel.class.st +++ b/repository/OpenPonk-Core/OPTestAbstractModel.class.st @@ -21,7 +21,10 @@ OPTestAbstractModel >> name [ { #category : 'accessing' } OPTestAbstractModel >> uuid [ - ^ uuid ifNil: [ uuid := '6875c7ff-b858-0d00-9c00-47750005dc5d' ] + + ^ uuid ifNil: [ + uuid := '6875c7ff-b858-0d00-9c00-4775' + , self hash printStringHex asLowercase ] ] { #category : 'accessing' } diff --git a/repository/OpenPonk-Core/OPTestEntityControllerTest.class.st b/repository/OpenPonk-Core/OPTestEntityControllerTest.class.st deleted file mode 100644 index f87d9327..00000000 --- a/repository/OpenPonk-Core/OPTestEntityControllerTest.class.st +++ /dev/null @@ -1,216 +0,0 @@ -Class { - #name : 'OPTestEntityControllerTest', - #superclass : 'OPBaseControllerTest', - #category : 'OpenPonk-Core-Controllers - Tests', - #package : 'OpenPonk-Core', - #tag : 'Controllers - Tests' -} - -{ #category : 'accessing' } -OPTestEntityControllerTest >> controllerClass [ - ^ OPTestEntityController -] - -{ #category : 'accessing' } -OPTestEntityControllerTest >> diagramControllerClass [ - ^ OPTestDiagramController -] - -{ #category : 'accessing' } -OPTestEntityControllerTest >> diagramModelClass [ - ^ OPTestContainerModel -] - -{ #category : 'accessing' } -OPTestEntityControllerTest >> modelClass [ - ^ OPTestEntityModel -] - -{ #category : 'tests - connecting' } -OPTestEntityControllerTest >> testAddAsSourceAndTargetForRelation [ - | sourceModel targetModel relationController relationModel | - sourceModel := self newModel. - targetModel := self newModel. - diagramController model - add: sourceModel; - add: targetModel. - diagramController showAllElements. - relationController := diagramController - newControllerFor: OPTestRelationModel new. - (diagramController controllerForModel: sourceModel) - addAsSourceFor: relationController. - (diagramController controllerForModel: targetModel) - addAsTargetFor: relationController. - relationModel := relationController model. - self - assert: (diagramController controllers includes: relationController). - self - assert: diagramController model entities asArray - equals: (Array with: sourceModel with: targetModel with: relationModel). - self assert: relationModel source equals: sourceModel. - self assert: relationModel target equals: targetModel -] - -{ #category : 'tests - connecting' } -OPTestEntityControllerTest >> testAddAsSourceAndTargetForRelationToSelf [ - | relationController relationModel | - controller model: model. - diagramController model add: model. - controller showWithoutDependentInDiagram: diagramController. - relationController := diagramController - newControllerFor: OPTestRelationModel new. - controller addAsSourceFor: relationController. - controller addAsTargetFor: relationController. - relationModel := relationController model. - self - assertCollection: diagramController controllers asSet - equals: - {controller. - relationController} asSet. - self - assertCollection: diagramController model entities asSet - equals: - {model. - relationModel} asSet. - self assert: relationModel source equals: model. - self assert: relationModel target equals: model -] - -{ #category : 'tests - connecting' } -OPTestEntityControllerTest >> testAddAsSourceForRelation [ - | relationController | - relationController := diagramController - newControllerFor: OPTestRelationModel new. - controller addAsSourceFor: relationController. - self assert: diagramController controllers asArray equals: {}. - self assert: relationController source equals: controller -] - -{ #category : 'tests - controllers' } -OPTestEntityControllerTest >> testAddController [ - controller model: model. - diagramController addController: controller. - self assert: (diagramController controllerForModel: model) equals: controller. - self assert: controller diagramController equals: diagramController -] - -{ #category : 'tests - connecting' } -OPTestEntityControllerTest >> testCanBeSourceForRelation [ - self - assert: - (controller - canBeSourceFor: (diagramController newControllerFor: OPTestRelationModel new)) -] - -{ #category : 'tests - connecting' } -OPTestEntityControllerTest >> testCanBeTargetForRelation [ - self - assert: - (controller - canBeTargetFor: (diagramController newControllerFor: OPTestRelationModel new)) -] - -{ #category : 'tests - construction' } -OPTestEntityControllerTest >> testCreateAndShow [ - - | subModel | - controller - createModelIn: diagramController model - andShowInDiagram: diagramController. - self assert: diagramController model entities isNotEmpty. - subModel := diagramController model entities first. - self - assert: diagramController controllers asArray - equals: { controller }. - self assert: - (diagramController canvas nodes includes: controller roassalShape) -] - -{ #category : 'tests - construction' } -OPTestEntityControllerTest >> testCreateModel [ - controller createModelIn: diagramController model. - self assert: controller model isNotNil. - self assert: diagramController model entities asArray equals: {controller model} -] - -{ #category : 'tests - controllers' } -OPTestEntityControllerTest >> testFigureForModel [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: (diagramController roassalShapeForModel: model) - equals: controller roassalShape -] - -{ #category : 'tests - construction' } -OPTestEntityControllerTest >> testFigureWasRendered [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self assert: - (diagramController canvas nodes includes: controller roassalShape) -] - -{ #category : 'tests - controllers' } -OPTestEntityControllerTest >> testModelForFigure [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: - (diagramController modelForFigure: controller roassalShape) - equals: model -] - -{ #category : 'tests - controllers' } -OPTestEntityControllerTest >> testNewController [ - controller := diagramController newControllerFor: model. - self assert: controller class equals: self controllerClass -] - -{ #category : 'tests - ui interaction' } -OPTestEntityControllerTest >> testOpenInForm [ - - | form | - controller model: model. - form := OPDynamicForm new. - diagramController stub form willReturn: form. - self assert: form layout children isEmpty. - diagramController openInForm: controller. - self assert: form layout children isNotEmpty -] - -{ #category : 'tests - destruction' } -OPTestEntityControllerTest >> testRemoveController [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - controller removeController. - self - should: [ diagramController controllerForModel: model ] - raise: NotFound. - self assert: diagramController canvas nodes asArray equals: { } -] - -{ #category : 'tests - destruction' } -OPTestEntityControllerTest >> testRemoveFigureAndModel [ - - diagramController model entities add: model. - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - diagramController removeFromCanvas: controller roassalShape. - self assert: diagramController controllers asArray equals: { }. - self assert: diagramController model entities asArray equals: { } -] - -{ #category : 'tests - construction' } -OPTestEntityControllerTest >> testShowInDiagram [ - - controller model: model. - controller showWithoutDependentInDiagram: diagramController. - self - assert: (diagramController controllerForRoassalShape: - controller roassalShape) - equals: controller -] diff --git a/repository/OpenPonk-Spec/OPCanvasExporter.class.st b/repository/OpenPonk-Spec/OPCanvasExporter.class.st new file mode 100644 index 00000000..248339a2 --- /dev/null +++ b/repository/OpenPonk-Spec/OPCanvasExporter.class.st @@ -0,0 +1,120 @@ +Class { + #name : 'OPCanvasExporter', + #superclass : 'Object', + #instVars : [ + 'silently', + 'diagramController', + 'file' + ], + #category : 'OpenPonk-Spec-Export', + #package : 'OpenPonk-Spec', + #tag : 'Export' +} + +{ #category : 'as yet unclassified' } +OPCanvasExporter class >> exportDiagramController: aDiagramController to: aFileReference [ + + self new + diagramController: aDiagramController to: aFileReference; + export +] + +{ #category : 'as yet unclassified' } +OPCanvasExporter class >> exportSilentlyDiagramController: aDiagramController to: aFileReference [ + + self silent + diagramController: aDiagramController to: aFileReference; + export +] + +{ #category : 'as yet unclassified' } +OPCanvasExporter class >> silent [ + + ^ self new + silent; + yourself +] + +{ #category : 'accessing' } +OPCanvasExporter >> canvas [ + + ^ self diagramController canvas +] + +{ #category : 'accessing' } +OPCanvasExporter >> diagramController [ + + ^ diagramController +] + +{ #category : 'accessing' } +OPCanvasExporter >> diagramController: aDiagramController to: aFileReference [ + + diagramController := aDiagramController. + file := aFileReference +] + +{ #category : 'actions' } +OPCanvasExporter >> export [ + + | jobBlock | + self diagramController deselectAll. + + jobBlock := [ :job | + job title: 'Exporting diagram'. + [ self exportInJob: job ] ensure: [ + job progress: 0.8. + self canvas signalUpdate ] ]. + + silently ifTrue: [ ^ jobBlock value: Job new ]. + jobBlock asJob run. + + self showFinishedPopup +] + +{ #category : 'private - actions' } +OPCanvasExporter >> exportInJob: job [ + + self setupExporter export +] + +{ #category : 'initialization' } +OPCanvasExporter >> initialize [ + + super initialize. + silently := false +] + +{ #category : 'hooks' } +OPCanvasExporter >> roassalExporter [ + + ^ self subclassResponsibility +] + +{ #category : 'hooks' } +OPCanvasExporter >> setupExporter [ + + ^ self roassalExporter + fileName: file pathString; + zoomToShapes; + yourself +] + +{ #category : 'actions' } +OPCanvasExporter >> showFinishedPopup [ + + UIManager default + inform: (String streamContents: [ :s | + s << 'Diagram saved to ' << file pathString. + s + cr; + cr. + "s << 'Click to open location' commented as it does not work" ]) + actionOnClick: [ file openInOSFileBrowser ] +] + +{ #category : 'accessing' } +OPCanvasExporter >> silent [ + + silently := true +] diff --git a/repository/OpenPonk-Spec/OPCanvasPDFExporter.class.st b/repository/OpenPonk-Spec/OPCanvasPDFExporter.class.st new file mode 100644 index 00000000..32245644 --- /dev/null +++ b/repository/OpenPonk-Spec/OPCanvasPDFExporter.class.st @@ -0,0 +1,13 @@ +Class { + #name : 'OPCanvasPDFExporter', + #superclass : 'OPCanvasExporter', + #category : 'OpenPonk-Spec-Export', + #package : 'OpenPonk-Spec', + #tag : 'Export' +} + +{ #category : 'hooks' } +OPCanvasPDFExporter >> roassalExporter [ + + ^ self canvas pdfExporter +] diff --git a/repository/OpenPonk-Spec/OPCanvasPNGExporter.class.st b/repository/OpenPonk-Spec/OPCanvasPNGExporter.class.st new file mode 100644 index 00000000..2e33a7cb --- /dev/null +++ b/repository/OpenPonk-Spec/OPCanvasPNGExporter.class.st @@ -0,0 +1,56 @@ +Class { + #name : 'OPCanvasPNGExporter', + #superclass : 'OPCanvasExporter', + #instVars : [ + 'zoom' + ], + #category : 'OpenPonk-Spec-Export', + #package : 'OpenPonk-Spec', + #tag : 'Export' +} + +{ #category : 'as yet unclassified' } +OPCanvasPNGExporter class >> exportDiagramController: aDiagramController to: aFileReference zoom: aZoom [ + + self new + diagramController: aDiagramController to: aFileReference zoom: aZoom; + export +] + +{ #category : 'as yet unclassified' } +OPCanvasPNGExporter class >> exportSilentlyDiagramController: aDiagramController to: aFileReference zoom: aZoom [ + + self silent + diagramController: aDiagramController + to: aFileReference + zoom: aZoom; + export +] + +{ #category : 'as yet unclassified' } +OPCanvasPNGExporter >> diagramController: aDiagramController to: aFileReference [ + + super diagramController: aDiagramController to: aFileReference. + zoom := 1.0 +] + +{ #category : 'as yet unclassified' } +OPCanvasPNGExporter >> diagramController: aDiagramController to: aFileReference zoom: aZoom [ + + self diagramController: aDiagramController to: aFileReference. + zoom := aZoom +] + +{ #category : 'hooks' } +OPCanvasPNGExporter >> roassalExporter [ + + ^ self canvas pngExporter +] + +{ #category : 'as yet unclassified' } +OPCanvasPNGExporter >> setupExporter [ + + ^ super setupExporter + cameraSetter: (OPRSCustomScaleCamSetter scale: zoom); + yourself +] diff --git a/repository/OpenPonk-Spec/OPCanvasPresenter.class.st b/repository/OpenPonk-Spec/OPCanvasPresenter.class.st index d7329583..54bbabec 100644 --- a/repository/OpenPonk-Spec/OPCanvasPresenter.class.st +++ b/repository/OpenPonk-Spec/OPCanvasPresenter.class.st @@ -62,114 +62,59 @@ OPCanvasPresenter >> editor [ ^ self owner ] +{ #category : 'toolbar' } +OPCanvasPresenter >> exportAsPdf [ + + self flag: 'default name not supported in file browser'. + OPExportImageDialog new + title: 'Choose a PDF file to export the diagram'; + okAction: [ :file :zoom | + OPCanvasPDFExporter + exportDiagramController: diagramController + to: file ]; + extensions: #( pdf ) named: 'PDF documents'; + open +] + { #category : 'toolbar' } OPCanvasPresenter >> exportAsPng [ self flag: 'default name not supported in file browser'. OPExportImageDialog new title: 'Choose a PNG file to export the diagram'; - okAction: [ :file :zoom | self exportCanvasToPng: file zoom: zoom ]; + okAction: [ :file :zoom | + OPCanvasPNGExporter + exportDiagramController: diagramController + to: file + zoom: zoom ]; extensions: #( png ) named: 'PNG images'; open ] +{ #category : 'toolbar' } +OPCanvasPresenter >> exportAsPng: aFile [ + + OPCanvasPNGExporter + exportDiagramController: diagramController + to: aFile +] + { #category : 'toolbar' } OPCanvasPresenter >> exportAsSvg [ self flag: 'default name not supported in file browser'. StFBSaveFileDialog new title: 'Choose a SVG file to export the diagram'; - okAction: [ :file | self exportCanvasToSvg: file ]; + okAction: [ :file | + OPCanvasSVGExporter + exportDiagramController: diagramController + to: file ]; extensions: #( svg ) named: 'SVG images'; "defaultName: self editor diagramController model name asFileName , '.svg';" open ] -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToPng: aFile [ - - self exportCanvasToPng: aFile silently: false -] - -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToPng: aFile silently: aSilentlyBoolean [ - - self - exportCanvasToPng: aFile - zoom: 1.0 - silently: aSilentlyBoolean -] - -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToPng: aFileReference zoom: aNumber [ - - self exportCanvasToPng: aFileReference zoom: aNumber silently: false -] - -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToPng: aFileReference zoom: aZoom silently: aSilentlyBoolean [ - - | originalZoom jobBlock | - originalZoom := self canvas camera scale. - self diagramController deselectAll. - - jobBlock := [ :job | - job title: 'Exporting diagram'. - [ - self canvas pngExporter - cameraSetter: (OPRSCustomScaleCamSetter scale: aZoom); - fileName: aFileReference pathString; - export ] ensure: [ - job progress: 0.8. - self canvas signalUpdate ] ]. - - aSilentlyBoolean ifTrue: [ ^ jobBlock value: Job new ]. - jobBlock asJob run. - - UIManager default - inform: (String streamContents: [ :s | - s << 'Image saved to ' << aFileReference pathString. - s - cr; - cr. - s << 'Click to open location' ]) - actionOnClick: [ aFileReference openInOSFileBrowser ] -] - -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToSvg: aFileReference [ - - self exportCanvasToSvg: aFileReference silently: false -] - -{ #category : 'toolbar' } -OPCanvasPresenter >> exportCanvasToSvg: aFileReference silently: aSilentlyBoolean [ - - | jobBlock | - self diagramController deselectAll. - - jobBlock := [ :job | - job title: 'Exporting diagram'. - - self canvas svgExporter - zoomToShapes; - fileName: aFileReference pathString; - export ]. - - aSilentlyBoolean ifTrue: [ ^ jobBlock value: Job new ]. - jobBlock asJob run. - - UIManager default - inform: (String streamContents: [ :s | - s << 'Image saved to ' << aFileReference pathString. - s - cr; - cr. - s << 'Click to open location' ]) - actionOnClick: [ aFileReference openInOSFileBrowser ] -] - { #category : 'initialization' } OPCanvasPresenter >> initialize [ diff --git a/repository/OpenPonk-Spec/OPCanvasSVGExporter.class.st b/repository/OpenPonk-Spec/OPCanvasSVGExporter.class.st new file mode 100644 index 00000000..c1360395 --- /dev/null +++ b/repository/OpenPonk-Spec/OPCanvasSVGExporter.class.st @@ -0,0 +1,13 @@ +Class { + #name : 'OPCanvasSVGExporter', + #superclass : 'OPCanvasExporter', + #category : 'OpenPonk-Spec-Export', + #package : 'OpenPonk-Spec', + #tag : 'Export' +} + +{ #category : 'hooks' } +OPCanvasSVGExporter >> roassalExporter [ + + ^ self canvas svgCairoExporter +] diff --git a/repository/OpenPonk-Spec/OPDiagramRemoveFigureCommand.class.st b/repository/OpenPonk-Spec/OPDiagramRemoveFigureCommand.class.st index bf191e78..3c6397f3 100644 --- a/repository/OpenPonk-Spec/OPDiagramRemoveFigureCommand.class.st +++ b/repository/OpenPonk-Spec/OPDiagramRemoveFigureCommand.class.st @@ -102,6 +102,6 @@ OPDiagramRemoveFigureCommand >> unsafeExecute [ diagramController deselectAll. figures do: [ :each | (diagramController hasControllerForFigure: each) ifTrue: [ - diagramController removeFromCanvas: each ] ]. + diagramController removeModelOfRoassalShape: each ] ]. canvas signalUpdate ] diff --git a/repository/OpenPonk-Spec/OPEditor.class.st b/repository/OpenPonk-Spec/OPEditor.class.st index 52328fbd..0656ed0f 100644 --- a/repository/OpenPonk-Spec/OPEditor.class.st +++ b/repository/OpenPonk-Spec/OPEditor.class.st @@ -65,6 +65,24 @@ OPEditor class >> developerToolbarMenu: aBuilder [ aBuilder withSeparatorAfter ] +{ #category : 'toolbar' } +OPEditor class >> diagramExportMenu: aBuilder [ + + (aBuilder item: #diagramExport) + label: 'Export diagram as...'; + icon: (self iconNamed: #smallScreenshot). + + (aBuilder item: 'Export as PNG...') + parent: #diagramExport; + action: [ aBuilder model canvasPresenter exportAsPng ]. + (aBuilder item: 'Export as SVG...') + parent: #diagramExport; + action: [ aBuilder model canvasPresenter exportAsSvg ]. + (aBuilder item: 'Export as PDF...') + parent: #diagramExport; + action: [ aBuilder model canvasPresenter exportAsPdf ] +] + { #category : 'settings' } OPEditor class >> layoutName [ @@ -112,12 +130,7 @@ OPEditor class >> toolbarMenu: aBuilder [ self developerToolbarMenu: aBuilder. - (aBuilder item: 'Export as PNG...') - icon: (self iconNamed: #smallScreenshot); - action: [ aBuilder model canvasPresenter exportAsPng ]. - (aBuilder item: 'Export as SVG...') - icon: (self iconNamed: #smallScreenshot); - action: [ aBuilder model canvasPresenter exportAsSvg ] + self diagramExportMenu: aBuilder ] { #category : 'accessing - spec' } diff --git a/repository/OpenPonk-Spec/OPExportImageDialog.class.st b/repository/OpenPonk-Spec/OPExportImageDialog.class.st index 7ac0f405..b9df9514 100644 --- a/repository/OpenPonk-Spec/OPExportImageDialog.class.st +++ b/repository/OpenPonk-Spec/OPExportImageDialog.class.st @@ -23,7 +23,7 @@ OPExportImageDialog class >> defaultLayout [ add: (SpBoxLayout newLeftToRight add: SpNullPresenter new; add: #zoomLabel expand: false; - add: #zoomText expand: false; + add: #zoomText width: 30; add: #zoomPercentageLabel expand: false; yourself) expand: false; diff --git a/repository/OpenPonk-Spec/OPShowHideTabContentPresenter.class.st b/repository/OpenPonk-Spec/OPShowHideTabContentPresenter.class.st index bc96ba84..2be4bf22 100644 --- a/repository/OpenPonk-Spec/OPShowHideTabContentPresenter.class.st +++ b/repository/OpenPonk-Spec/OPShowHideTabContentPresenter.class.st @@ -27,6 +27,7 @@ OPShowHideTabContentPresenter >> childrenFor: anItem [ { #category : 'initialization' } OPShowHideTabContentPresenter >> connectPresenters [ + self whenSelectionChangedDo: [ self updateSelectedItems ] ] @@ -134,12 +135,9 @@ OPShowHideTabContentPresenter >> unselected: aRemovedItem [ { #category : 'accessing' } OPShowHideTabContentPresenter >> updateSelectedItems [ + selectedItems := self findSelectedItems. - tree adapter - ifNotNil: [ :treeAdapter | - treeAdapter widget dataSource - updateData; - expandAll ]. + tree refresh. ^ selectedItems ]