Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 0058 #60

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/Pyramid-Bloc/PyramidElementsManipulationHelper.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Class {
#name : #PyramidElementsManipulationHelper,
#superclass : #Object,
#category : #'Pyramid-Bloc-utils'
}

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> accumulateChildrenOf: aBlElement in: aCollection [

aCollection add: aBlElement.
aBlElement childrenDo: [ :each |
self accumulateChildrenOf: each in: aCollection ]
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> accumulateParentsOf: aCollectionOfBlElement in: result [

| elementToTest onCollection nextCollection shouldKeepIt |
shouldKeepIt := true.
aCollectionOfBlElement isEmpty ifTrue: [ ^ self ].
aCollectionOfBlElement size = 1 ifTrue: [
result add: aCollectionOfBlElement first.
^ self ].

elementToTest := aCollectionOfBlElement first.
onCollection := aCollectionOfBlElement allButFirst.
nextCollection := OrderedCollection new.

onCollection do: [ :each |
(each hasParent: elementToTest) ifFalse: [
nextCollection add: each ].
(shouldKeepIt and: [ elementToTest hasParent: each ]) ifTrue: [
shouldKeepIt := false ] ].
shouldKeepIt ifTrue: [ result add: elementToTest ].
self accumulateParentsOf: nextCollection in: result
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> flattenChildrenOfCollection: aCollection [
"Consider:
A1->A2-A3.
B1->B2->B3.

col := { A1 . B2 }

PyramidElementsManipulationHelper flattenChildrenOfCollection: col
returns
{ A1 . A2 . A3 . B2 . B3 }
"

| ret |
ret := OrderedCollection new.
aCollection do: [ :each | self accumulateChildrenOf: each in: ret ].
^ ret
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelper class >> onlyParents: aCollectionOfBlElement [
"return a collection whithout any parent-child relation.
Example:
consider this as all elements
A1->A2->A3
B1->B2->B3.
C1->C2->C3.
D1->D2->D3.

selection := {A1 . B1 . B2 . C1 . C3}.
PyramidElementsManipulationHelper onlyParents: selection
returns: { A1 . B1 . C1 }
"

| result |
aCollectionOfBlElement isEmpty ifTrue: [ ^ { } ].
aCollectionOfBlElement size = 1 ifTrue: [
^ { aCollectionOfBlElement first } ].
result := OrderedCollection new.
self accumulateParentsOf: aCollectionOfBlElement in: result.
^ result asArray
]
80 changes: 80 additions & 0 deletions src/Pyramid-Bloc/PyramidElementsManipulationHelperTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Class {
#name : #PyramidElementsManipulationHelperTest,
#superclass : #TestCase,
#category : #'Pyramid-Bloc-utils'
}

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelperTest >> arrayOf3Elements [

| e1 e2 e3|
e1 := BlElement new.
e2 := BlElement new.
e3 := BlElement new.

e1 addChild: e2.
e2 addChild: e3.
^ { e1 . e2 . e3 }
]

{ #category : #'as yet unclassified' }
PyramidElementsManipulationHelperTest >> arrayOfElements [

"
A1 -> A2 -> A3.
B1 -> B2 -> B3.
C1 -> C2 -> C3.
D1 -> D2 -> D3.
"

|arrayA arrayB arrayC arrayD|

arrayA := self arrayOf3Elements.
arrayB := self arrayOf3Elements.
arrayC := self arrayOf3Elements.
arrayD := self arrayOf3Elements.

^ { arrayA. arrayB. arrayC. arrayD }

]

{ #category : #tests }
PyramidElementsManipulationHelperTest >> testFlattenChildrenOfCollection [

| arrayOfElements test result |
arrayOfElements := self arrayOfElements.
test := {
(arrayOfElements at: 1) first.
(arrayOfElements at: 2) first firstChild }.
result := PyramidElementsManipulationHelper
flattenChildrenOfCollection: test.
self assert: result size equals: 5.
self assert: (result includesAll: {
(arrayOfElements at: 1) first.
(arrayOfElements at: 1) first firstChild.
(arrayOfElements at: 1) first firstChild firstChild.
(arrayOfElements at: 2) first firstChild.
(arrayOfElements at: 2) first firstChild firstChild })
]

{ #category : #tests }
PyramidElementsManipulationHelperTest >> testOnlyParents [
"selection := {A1 . B1 . B2 . C1 . C3}.
PyramidElementsManipulationHelper onlyParents: selection
returns: { A1 . B1 . C1 }"

| arrayOfElements test result |
arrayOfElements := self arrayOfElements.
test := {
(arrayOfElements at: 1) first.
(arrayOfElements at: 2) first.
(arrayOfElements at: 2) first firstChild.
(arrayOfElements at: 3) first.
(arrayOfElements at: 3) first firstChild firstChild }.
result := PyramidElementsManipulationHelper onlyParents: test.
self assert: result size equals: 3.
self assert: (result includesAll: {
(arrayOfElements at: 1) first.
(arrayOfElements at: 2) first .
(arrayOfElements at: 3) first})
]
40 changes: 22 additions & 18 deletions src/Pyramid-Bloc/PyramidLogo.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PyramidLogo class >> logoMedium [
"This class has been generated using Pyramid.

By: YannLEGOFF
2023-07-31 13:44:18"
2023-08-07 13:52:07"

<pySTON>
^ '[
Expand Down Expand Up @@ -43,7 +43,13 @@ PyramidLogo class >> logoMedium [
#geometry : BlPolygonGeometry {
#extent : Point [ 50.0, 50.0 ],
#pathCache : BlPathCache {
#geometry : @12
#geometry : @12,
#strokedBounds : BlBounds {
#left : -0.5,
#top : -0.5,
#right : 30.5,
#bottom : 60.5
}
},
#vertices : [
Point [ 0.0, 34.0 ],
Expand Down Expand Up @@ -82,11 +88,7 @@ PyramidLogo class >> logoMedium [
#identifier : #C
}
},
#layout : BlBasicLayout { },
#eventDispatcher : BlElementEventDispatcher {
#owner : @2,
#handlers : [ ]
}
#layout : BlBasicLayout { }
},
BlElement {
#children : BlChildrenArray [ ],
Expand All @@ -111,7 +113,13 @@ PyramidLogo class >> logoMedium [
#geometry : BlPolygonGeometry {
#extent : Point [ 50.0, 50.0 ],
#pathCache : BlPathCache {
#geometry : @42
#geometry : @41,
#strokedBounds : BlBounds {
#left : 29.5,
#top : -0.5,
#right : 70.5,
#bottom : 60.5
}
},
#vertices : [
Point [ 70.0, 30.0 ],
Expand All @@ -121,14 +129,14 @@ PyramidLogo class >> logoMedium [
},
#border : BlBorder {
#paint : BlColorPaint {
#color : @21
#color : @22
},
#width : 1,
#style : BlStrokeStyle {
#lineCap : @23,
#lineJoin : @24,
#lineCap : @24,
#lineJoin : @25,
#miterLimit : 4.0,
#dashArray : @25,
#dashArray : @26,
#dashOffset : 0.0
},
#opacity : 1.0
Expand All @@ -138,18 +146,14 @@ PyramidLogo class >> logoMedium [
#color : Color [ #white ]
}
},
#outskirts : @29
#outskirts : @30
},
#userData : IdentityDictionary {
#elementId : BlElementNamedId {
#identifier : #D
}
},
#layout : @32,
#eventDispatcher : BlElementEventDispatcher {
#owner : @35,
#handlers : [ ]
}
#layout : @33
}
]'
]
Expand Down
2 changes: 1 addition & 1 deletion src/Pyramid-Bloc/PyramidSearchAndSelectPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PyramidSearchAndSelectPresenter >> codeIsForAll [
self projectModel ifNil: [ ^ self ].
self codePresenter interactionModel:
(SpCodeObjectInteractionModel on:
(PyramidTreeToFlat flattenChildrenOfCollection:
(PyramidElementsManipulationHelper flattenChildrenOfCollection:
self projectModel roots))
]

Expand Down
Loading