~hilaire-fernandes/drgeo/trunk

« back to all changes in this revision

Viewing changes to src/DrGeoII-Core/DrGCoordinatesBuilder.class.st

  • Committer: Hilaire Fernandes
  • Date: 2017-11-15 13:17:03 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20171115131703-pz09obavthi53ebt
DrGeo code under Tonel file format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"
 
2
A builder for to build:
 
3
- the coordinates of a point
 
4
- the equation of a circle
 
5
- the equation of a line
 
6
"
 
7
Class {
 
8
        #name : #DrGCoordinatesBuilder,
 
9
        #superclass : #DrGMathItemBuilder,
 
10
        #instVars : [
 
11
                'pointA',
 
12
                'vector',
 
13
                'circle',
 
14
                'line'
 
15
        ],
 
16
        #category : #'DrGeoII-Core-Builder'
 
17
}
 
18
 
 
19
{ #category : #documentation }
 
20
DrGCoordinatesBuilder class >> description [
 
21
        ^ 'Vector or point coordinates, circle or line equation.' translated
 
22
]
 
23
 
 
24
{ #category : #documentation }
 
25
DrGCoordinatesBuilder class >> title [
 
26
        ^ 'Coordinates, equation' translated
 
27
]
 
28
 
 
29
{ #category : #private }
 
30
DrGCoordinatesBuilder >> addItem: aMathItemCollection at: aPoint [
 
31
        | item |
 
32
        point := aPoint.
 
33
        item := aMathItemCollection first.
 
34
        item isPointItem ifTrue: [^ pointA := item].
 
35
        item isCircleItem ifTrue: [^ circle := item].
 
36
        item isLineItem ifTrue: [^ line := item].
 
37
        item isVectorItem ifTrue: [^ vector := item]
 
38
]
 
39
 
 
40
{ #category : #accessing }
 
41
DrGCoordinatesBuilder >> arguments [
 
42
        ^ Array with: ({pointA. vector . line . circle } detect: [:i | i isNil not] ifNone: [nil]) with: point
 
43
]
 
44
 
 
45
{ #category : #testing }
 
46
DrGCoordinatesBuilder >> isWanted: aMathItemCollection [ 
 
47
        ^ aMathItemCollection notEmpty 
 
48
                and: [aMathItemCollection first isPointItem
 
49
                        or: [aMathItemCollection first isLineItem
 
50
                        or: [aMathItemCollection first isCircleItem
 
51
                        or: [aMathItemCollection first isVectorItem]]]]
 
52
]
 
53
 
 
54
{ #category : #'as yet unclassified' }
 
55
DrGCoordinatesBuilder >> itemInstanceFrom: node [
 
56
"build an item from a XML description"
 
57
"this builder can create multiple item at once (coordinates X and Y), so we need
 
58
to select the one we want"
 
59
        | nodeType |
 
60
        (self parentsById: node) do: [:each |   self addItem: {each} at: 0@0].
 
61
        nodeType := (node  attributeAt: #type) asSymbol.
 
62
        ^ self getItem detect: [:item | item nodeType = nodeType]
 
63
 
 
64
]
 
65
 
 
66
{ #category : #constant }
 
67
DrGCoordinatesBuilder >> mathItemClass [ 
 
68
        pointA ifNotNil: [^{DrGValuePtabscissaItem      . DrGValuePtordinateItem}].
 
69
        vector ifNotNil: [^{DrGValueVectorabscissaItem . DrGValueVectorordinateItem}].
 
70
        circle ifNotNil: [^ DrGEquationCircleItem].
 
71
        line ifNotNil: [^ DrGEquationLineItem]
 
72
]
 
73
 
 
74
{ #category : #xml }
 
75
DrGCoordinatesBuilder >> postProcess: item from: node [
 
76
        super postProcess: item from: node.
 
77
        self parseValuePosition: node of: item.
 
78
]
 
79
 
 
80
{ #category : #testing }
 
81
DrGCoordinatesBuilder >> readyToBuild [ 
 
82
        ^ {pointA. vector . line . circle } anySatisfy: [:i | i isNil not]
 
83
                
 
84
]
 
85
 
 
86
{ #category : #updating }
 
87
DrGCoordinatesBuilder >> reset [
 
88
        super reset.
 
89
        pointA := vector := circle := line := nil
 
90
]