Sommario Introduzione 6 1 La norma IEC 1131-3 8 1.1 Introduzione alle variabili e alle unità di organizzazione di programma 9 1.2 Dichiarazione di conformità alla norma 11 1.2.1 Conformità (1.5) 11 1.3 Elementi Comuni(2) 13 1.3.1 I tipi elementari, generici e derivati (2.3) 13 1.3.2 VARIABILI (2.4) 16 Dichiarazione (2.4.3) 19 1.4 POU - Unità Organizzative di Programma (2.5) 21 1.4.1 Funzioni (2.5.1) 22 1.4.2 Blocchi funzionali (2.5.2) 24 1.5 Elementi di Configurazione (2.7) 26 1.6 SFC - Sequential Functional Chart (2.6) 32 1.6.1 Controllo delle azioni (2.6.4.5) 36 1.6.2 Regole di evoluzione (2.6.5) 36 2 ISaGRAF 39 2.1 THE WORKBENCH (ambiente di lavoro) 40 2.1.1 THE PROJECT (il progetto) 41 2.1.2 LINK ARCHITECTURE (architettura dei collegamenti) 41 2.1.3 RESOURCE (Risorsa) 42 PARAMETRI 43 GRUPPO DI VARIABILI 44 PROGRAMMI 44 PROPRIETA’ DELLA RISORSA 45 2.1.4 DATA LINK (collegamento di dati) 46 2.1.5 ARCHITETTURA HARDWARE 46 2.1.6 DIZIONARIO (Dictionary) 48 VALORI INIZIALI 52 GRIGLIA PARAMETRI 53 GRIGLIA TIPI STRUTTURATI 54 GRIGLIA COSTANTI 55 1
271
Embed
Sommario - TiscaliNewsweb.tiscali.it/antosc/mywork/files/tesi.pdf · 4.1.3 Tipi di Azioni 85 Azione Continuata 86 Azione Condizionata 86 Azione Limitata nel Tempo 86 Azione impulsiva
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
SommarioIntroduzione 6
1 La norma IEC 1131-3 81.1 Introduzione alle variabili e alle unità di organizzazione di
programma 91.2 Dichiarazionedi conformitàalla norma 111.2.1 Conformità (1.5) 111.3 Elementi Comuni(2) 131.3.1 I tipi elementari, generici ederivati (2.3) 131.3.2 VARIABILI (2.4) 16
Dichiarazione (2.4.3) 191.4 POU - UnitàOrganizzative di Programma(2.5) 211.4.1 Funzioni (2.5.1) 221.4.2 Blocchi funzionali (2.5.2) 241.5 Elementi di Configurazione (2.7) 261.6 SFC - Sequential Functional Chart (2.6) 321.6.1 Controllo delleazioni (2.6.4.5) 361.6.2 Regoledi evoluzione (2.6.5) 36
2 ISaGRAF 392.1 THE WORKBENCH (ambientedi lavoro) 402.1.1 THE PROJECT (il progetto) 412.1.2 LINK ARCHITECTURE (architetturadei collegamenti) 412.1.3 RESOURCE (Risorsa) 42
PARAMETRI 43GRUPPO DI VARIABILI 44PROGRAMMI 44PROPRIETA’ DELLA RISORSA 45
2.1.4 DATA LINK (collegamento di dati) 462.1.5 ARCHITETTURA HARDWARE 462.1.6 DIZIONARIO (Dictionary) 48
VALORI INIZIALI 52GRIGLIA PARAMETRI 53GRIGLIA TIPI STRUTTURATI 54GRIGLIA COSTANTI 55
1
2.1.7 I/O WIRING SECTION (sezionecollegamenti I/O) 552.2 THE TARGET 572.3 LINGUAGGI 582.4 LINGUAGGIO SFC 632.4.1 AZIONI COLLEGATE AI PASSI 64
2.4.2 TRANSITIONS (transizioni) 662.4.3 EVOLUZIONE DINAMICA 672.4.4 HIERARCHY (gerarchia) 672.5 COMPATIBILITA’ CON LA NORMA 682.5.1 PROGRAMMAZIONE SFC 682.5.2 TIPI DI DATI 702.5.3 TIPI DI DATI DERIVATI 712.5.4 TASKS 71
3 RSLogix 5 723.1 Il Progetto 723.1.1 Filesdel Progetto 753.2 L’ambientedi lavoro 753.3 Privilegi di classe 773.4 Sequential Functional Chart 773.4.1 Passo 783.4.2 Transizione 783.4.3 Divergenzaselettiva 793.4.4 Divergenzaparallela 793.4.5 Parametri della listadi azioni 803.4.6 Forzareuna transizione 823.4.7 GOTO 823.4.8 LABEL 823.4.9 MacroFase (SFC macro) 823.5 Compatibilitàcon la norma 82
2
4 Una versione ‘‘accademica’’ del Sequential FunctionalChar t 84
4.1 Gli elementi di base 844.1.1 Passi 844.1.2 Transizioni 854.1.3 Tipi di Azioni 85
AzioneContinuata 86AzioneCondizionata 86AzioneLimitatanel Tempo 86Azione impulsiva 86AzioneRitardata 87AzioneMemorizzata 87
5 Sviluppo softwaredi un editor SFC 905.1 Perchè realizzareun editor SFC 905.2 Obiettivi del programma 925.3 Documentazioneesternadel programma 945.3.1 MotivazioneGenerale 945.3.2 Istruzioni per l’uso 95
� deve essere accompagnato da un documento che descrive separatamente le
caratteristiche del sistema proibite o non specif icate in questo documento e
descritte comeestensioneal linguaggio� ancheper tali estensioni deve trattaregli errori comedefinito sopra� non deveutilizzarenessun nomedi funzioneo di blocco funzionalestandard che
non abbia il comportamento specificato in questo documento
12
� deveessereaccompagnato daun documento chedescriveformalmente lasintassi
di linguaggio confomementeall’allegato A
Nel caso in cui il caricamento o lacompilazionedi un programmavengano interrotti
acausadi alcune limitazioni di tabelle, ecc., unadichiarazione incompletadel tipo
‘‘nessuna non conformità èstata rilevata, ma l’esaminazioneè incompleta’’
soddisferà comunquealleprescrizioni di questo paragrafo.
Per i programmi invece laconformità richiede :
� di utilizzaresolo lecaratteristichespecificateinquestodocumentoper lospecif ico
linguaggio utilizzato� di non utilizzarenessunacaratteristicaidentificatacomeestensionedi linguaggio.� di noncontaresualcunainterpretazioneparticolaredellecaratteristichedipendenti
dall’ implementazione
3 Elementi Comuni(2)
3.1 I tipi elementar i, gener ici eder ivati (2.3)
I tipi di dati elementari previsti dallaNormasonoelencati nellatabella1erappresentano
un insieme strutturalmente completo per soddisfare le esigenze di programmazione di
ogni utentePLC.
La Norma prevede inoltre l’utilizzo di dati ‘‘generici’’ contraddistinti dal prefisso
‘‘ANY’’ e che vengono utilizzati per generare funzioni o operatori ‘‘sovraccaricati’’
(overloaded) che cioè accettano tipi diversi come parametri. Essi sono organizzati
gerarchicamente come indicato in Tabella 2. Tale implementazione rappresenta in
praticalapossibilitàdi dichiarareuna var iabileindipendentementedal tipo equindi
13
N�
Parolachiave Tipo di dato Bits1 BOOL Booleano 12 SINT Intero corto 83 INT Intero 164 DINT Intero doppio 325 LINT Intero lungo 646 USINT Int. corto senzasegno 87 UINT Intero senzasegno 168 UDINT Int. doppio senzasegno 329 ULINT Int. lungo senzasegno 6410 REAL Reale 3211 LREAL Reale lungo 6412 TIME Durata Nota113 DATE Data Nota114 TIME_OF_DAY (TOD) Oradel giorno Nota115 DATE_AND_TIME (DT) Dataeoradel giorno Nota116 STRING Stringa Nota117 BYTE 8 bit 818 WORD 16 bit 1619 DWORD 32 bit 3220 LWORD 64 bit 64
Tabella 1: Tipi di dati elementari
di mantenere una certa compatibilità con la rappresentazione interna dei dati che,
in molti PLC, sono identif icati con semplici locazioni di memoria. Nei PLC Allen
Bradley, ad esempio, la memoria programmi è organizzata nei cosiddetti program files
di dimensioni massime fissatedal SistemaOperativo enumerati da0 a999. I primi tre
sono dichiarati di default comedati di uscita, di ingresso edi stato processore; agli altri
possonoessereassociatestrutturedati di tipocontatore, variabili binarie, temporizzatori,
variabili reali in virgolamobile, caratteri, strutturePID, ecc...
Come si vede dunque in questo tipo di processori non è possibile dichiarare
una struttura utente particolare ma bisogna attenersi a quelle preesistenti; la Norma
rappresenta allora un validissimo supporto ad una programmazione di più alto livello;
Gli identif icatori dellevariabili asingoloelemento, cioèquellecomunementeimpiegate
in ogni PLC, per laNormadevono rispettare lasintassi descrittadallaTabella3
La rappresentazione diretta deve essere provvista di uno speciale simbolo, formato
dalla concatenazione di un segno di percentuale ‘%’ , un prefisso di locazione e un
prefisso di taglia eda uno o più interi senzasegno, separati dapunti (.).
Il costruttore deve specif icare la corrispondenza tra la rappresentazione diretta e la
locazione fisica o logica per gli elementi indirizzati in ingresso o in uscita. Quando
una rappresentazione diretta è estesa con delle zone di interi separati da punti, essa
deveessere interpretatacomeun indirizzo gerarchico fisico o logico, con il campo più
a sinistra che rappresenta il livello più alto della gerarchia. Per esempio la variabile
16
%IW2.5.7.1 può rappresentare il primo canale (word) del settimo modulo nel quinto
rack del secondo bus di I/O di un sistemaacontrolloreprogrammabile.
L’utilizzazione di un indirizzamento gerarchico per permettere ad un programma in
un sistema PLC di accedere a dati di un altro PLC deve essere considerato come una
estensione di linguaggio. L’utilizzo di variabili direttamente rappresentate è consentito
solo nei Programmi, nelleConfigurazioni enelleRisorse. Il numero massimo di livelli
nellagerarchiaèun parametro proprio dell’ implementazione.
Esempi :
� %IW53 paroladellazonadegli ingressi� %MW30 paroladellazonadellamemoria� %MX41 oppure%M41 (laX può essereomessa) bit della zonadellamemoria� %MD48 doppiaparoladellazonadellamemoria� %MW4:8 tabelladi 8 parole� %MW0:X4 bit di rango 4 dellaparola interna%MW0� %QX21 oppure%Q21 (laX può essereomessa) bit dellazonadelleuscite
Parola chiave UtilizzazionedellevariabiliVAR InternaallaPOUVAR_INPUT Fornita dall’esterno, non modificabiledallaPOUVAR_OUTPUT Fornita dallaPOU alleentitàesterneVAR_IN_OUT Fornite dalleentitàesterne, può esseremodif. dallaPOUVAR_EXTERNAL FornitadallaConfigurazioneattraversoVAR_GLOBAL, può
esseremodificatadallaPOUVAR_GLOBAL Dichiarazionedi variabileglobaleVAR_ACCESS Dichiarazionedi percorso di accessoRETAIN Variabili avalore ritenutoCONSTANT CostanteAT Assegnamento di locazione
Tabella4: Dichiarazioni dellevariabili
o dati egestitegerarchicamentetrai programmi. Più chedi visibilitàsi potrebbeparlare
quindi di protezione.
La Norma impone ancora che ogni dichiarazione di programma, funzione o blocco
funzionale deve contenere all’ inizio almeno una parte dichiarativa che specifica
i tipi delle variabili utilizzate nelle unità organizzative di programma (POU). Tale
parte dichiarativa deve avere forma testuale con le parole chiave VAR, VAR_INPUT,
dichiarate dal costruttore, oppure stabilisce una corr ispondenza di Simboli/Indir izzi
(identif icativo variabile - rappresentazionediretta) in una tabelladi DataBaseal finedi
20
renderepiù agevolelacomprensionedei programmi chesfruttano levariabili altrimenti
direttamente rappresentate.
Un aspetto molto interessantechetroviamo tralepossibilitàdi dichiararelevariabili
è quello della keyword ‘AT’ che consente, senza bisogno di tabelle ecc.., di assegnare
direttamente ad un identificativo di variabile una locazione fisica specif icata da una
rappresentazionediretta :
VARPULSANTE AT %I X27 : BOOL; ( * i ngr esso bool eano * )START AT %QX25 : BOOL; ( * usci t a bool eana * )TEMPERATURA AT %I W28 : I NT; ( * i ngr . anal ogi co 16 bi t
* )END_VAR
La Norma prevede comunque che nel momento in cui l’assegnazione dell’ indirizzo
Una funzione deveesseredichiarata testualmenteo graficamente.
Ladichiarazione testualeconsistedei seguenti elementi :
La parola chiave FUNCTION, seguita da un identificatore che specif ica il nome
dellafunzione, il simbolo ‘duepunti’ (:), e il tipo di dato restituito dallafunzione. un costrutto VAR_INPUT...END_VAR, specificando il nome e i tipi degli
argomenti di ingresso alla funzione. un costrutto VAR...END_VAR, se richiesto, specificando il nome e i tipi delle
variabili internealla funzione. un ‘corpo della funzione’ (function body), scritto in uno dei linguaggi definiti in
questa parte o qualsiasi altro linguaggio come definito in 1.4.3, che specif ica le
operazioni che la funzione deve eseguire sui parametri di ingresso per assegnare
uno o più valori ad una variabile con lo stesso nome della funzione e che
(overloaded) e cioè può operare con dati in ingresso di tipi differenti dichiarati
all’ interno della funzione con un tipo ‘generico’ (ANY). Definisce inoltre un insieme
di Funzioni Standard (2.5.1.5).
4.2 Blocchi funzionali (2.5.2)
Oltre alle Funzioni la norma definisce i Blocchi Funzionali, che sono delle unità
di organizzazione che una volta eseguite forniscono uno o più valori. Al contrario
delle funzioni, tutte le variabili di uscita e le variabili interne necessarie alla struttura
devono conservareil loro valoretraun esecuzionedel blocco funzionaleelasuccessiva
chiamata. Ciò significa che una stessa chiamata, con gli stessi parametri in ingresso
al blocco, può non produrre la stessa uscita. Inoltre le variabili interne al blocco non
possono essere accessibili all’utente esterno.La visibilità di una istanza di un blocco
funzionale deve essere locale alla POU nella quale è istanziato, a meno che non venga
dichiarato in un blocco VAR_GLOBAL. Il nome del blocco può essere usato come
ingresso ad una funzione o ad un blocco funzionale se dichiarato come VAR_INPUT,
oppurecomevariabiledi ingresso/uscitasedichiarato come VAR_IN_OUT.
24
Un’ istanza di blocco funzionale può essere creata testualmente dichiarando un dato
di tipo ‘block type’ usando il costrutto VAR...END_VAR, oppure graficamente usando
una rappresentazionegraficadel blocco funzionale, con il nomedel blocco all’ interno,
e il nomechesi vuole istanziareal di sopradel blocco.
Le variabili di ingresso e di uscita di un’ istanza di un blocco funzionale possono
esere richiamate usando lo stesso formalismo dellestrutture.
Esempio di dichiarazione testuale :
VAR FF75 : SR ; END_VAR ( * di chi ar azi one* )
FF75( S1: =%I X1, R: =%I X2) ; ( * chi amat a* )
%QX3: =FF75. Q1; ( * assegnazi one di usci t a* )
Le istanze di blocchi funzionali possono essere dichiarate con il qualif icatore
RETAIN.
L’assegnazione di un valoread unavariabile di uscita di un blocco funzionalenon è
permessaeccetto chedall’ interno del blocco stesso. L’assegnazionedi un valoread una
variabiledi ingresso inveceèpermesso solo all’atto dellachiamataal blocco.
Un blocco funzionale deve essere dichiarato testualmente o graficamente in modo
molto simileaquello di una funzione.
Anche per i Blocchi funzionali la Norma ne definisce alcuni standard (2.5.2.3)
comuni a tutti i linguaggi di programmazione del PLC e che si possono raggruppare
in :
� elementi bistabili� rilevazionedi fronti� contatori� temporizzatori
25
� di comunicazione
5 Elementi di Configurazione (2.7)
Una configurazione è composta da r isorse, tasks, var iabili globali e percorsi
d’accesso. Essarappresentain praticaun processorefisico sul qualevengono istanziate
le risorse elemento Un esempio di dichiarazione testuale di configurazione conforme
allanormaèriportato di seguito:
CONFI GURATI ON CELL1VAR_GLOBAL w : UI NT; END_VARRESOURCE STATI ON_1 ON PROCESSOR_TYPE_1
VAR_GLOBAL z1 : BYTE; END_VARTASK SLOW_1( I NTERVAL : = t #20ms, PRI ORI TY : = 2) ;TASK FAST_1( I NTERVAL : = t #10ms, PRI ORI TY : = 1) ;PROGRAM P1 WI TH SLOW_1 :
F( x1 : = %I X1. 1) ;PROGRAM P2 : G( out 1 = w, FB1 WI TH SLOW_1, FB2
WI TH FAST_1) ;END_RESOURCERESOURCE STATI ON_2 ON PROCESSOR_TYPE_2
VAR_GLOBAL z2 : BOOL;AT %QW5 : I NT;
END_VARTASK PER_2 ( I NTERVAL : = t #50ms, PRI ORI TY : = 2) ;TASK I NT_2 ( SI NGLE : = z2, PRI ORI TY : = 1) ;PROGRAM P1 WI TH PER_2 :
F( x1 : = z2, x2 : = w) ;PROGRAM P4 WI TH I NT_2 :
H( HOUT1 = %QW5, FB1 WI TH PER_2) ;END_RESOURCEVAR_ACCESS
ABLE : STATI ON_1. %I X1. 1 : BOOL READ_ONLY;BACKER : STATI ON_1. P1. x2 : UI NT READ_ONLY;CHARLI E : STATI ON_1. z1 : BYTE;DOG : w : UI NT READ_ONLY;
26
ALPHA : STATI ON_2. P1. y1 : BYTE READ_ONLY;BETA : STATI ON_2. P4. HOUT1 : I NT READ_ONLY;GAMMA : STATI ON_2. z2 : BOOL READ_ONLY;
della transizione; saràspecificato con uno dei seguenti linguaggi :
– rete in LD o FBD
– listadi istruzioni IL
– assegnazionecon espressione booleana in linguaggio ST
34
Inoltre la Norma impone che la visibilità del nome della transizione deve essere
locale alla POU nella quale si trova e, durante il processo di valutazione della
condizione, deve considerarsi un errore una assegnazione di valore ad una variabile
chenon rappresenti l’ identif icatoredella transizione.
Per definireleazioni associateai passi puòessereutilizzatounbloccodi azione ossia
un elemento grafico formato da una variabile booleana e da un qualif icatore di azione,
aventi lo scopo di creareunacondizionedi validazioneper l’azioneassociata.
‘‘a’’�
‘‘b’’ ‘‘c’’‘‘d’’
Tabella5: Blocco tipo
Esso ècostituito da :
� ‘‘a’’ : un qualificatore d’azione a cui è associato una variabile booleana; può
essere omesso se il qualif icatoreè ‘N’ (none).� ‘‘b’’ : nomedell’azione� ‘‘c’’ : variabili booleane di ‘‘segnalazione’’ (può essere omesso se non ci sono
variabili di questo tipo.� ‘‘d’’ : azioneveraepropriaspecif icatautilizzando
– Linguaggio IL
– Linguaggio ST
– Linguaggio LD
– Linguaggio FBD
Il qualificatore di azioni deve essere collegato ad ogni associazione passo/azione
oppure ad ogni presenza di un blocco di azione. Il suo valore è legato a dei codici
specifici:
� nessuno (qualificatorenullo, non memorizzato),� N (non memorizzato)
35
� R (rimesso azero prioritario)� S(posizionato, memorizzato)� L (limitato nel tempo)� D (ritardato nel tempo)� P(impulso)� SD (memorizzato e ritardato)� DS (ritardato ememorizzato)� SL (memorizzato e limitato nel tempo)
6.1 Controllo delleazioni (2.6.4.5)
Per definire il comportamento e le regole per il controllo delle azioni viene definito
un blocco in linguaggio FBD chiamato ACTION_CONTROL che riceve in ingresso
i qualif icatori e ha in uscita una variabile booleana che sta ad indicare la attivazione
dell’azione. Chiaramente non è indispensabile che il blocco ACTION_CONTROL sia
implementato; è sufficiente che il comando di azioni sia equivalente alle regole fissate
dal signif icato dei qualif icatori.
6.2 Regoledi evoluzione(2.6.5)
Inizialmente l’SFC ècaratterizzato dall’avereuna fase inizialeattiva.
Unatransizioneèdettaabilitata (enabled) quando tutti i passi chelaprecedono sono
attivi. Il superamento avviene in corrispondenzadell’abilitazioneedell’avverarsi della
condizione associata. Il superamento della transizione causa la deattivazione di tutti i
passi che laprecedono e l’attivazionedi tutti i passi immediatamentea valle.
Tra una transizione e l’altra deve sempre esserci un passo; viceversa tra un passo e
l’altro deveesserepresenteuna transzione.
36
Quando il superamentodi unatransizionedeterminal’attivazionedi piùpassi si parla
di attivazionedi sequenzesimultaneeossiadi parallelismo, indicatograficamentedauna
doppia lineaorizzontale.
Teoricamente il tempo di superamento di una transizione può essere considerato
piccolo a piacere ma non può mai essere zero. Più transizioni che possono
essere superate contemporaneamente, devono esserlo nei limiti di tempo imposti dal
controllore.
La valutazione di una o più condizioni di transizione non deve essere effettuata
prima che l’effetto dell’attivazione della fase si sia propagato attraverso tutta l’unita
organizzativadi programmaall’ interno dellaquale la faseèstatadichiarata.
Importanza particolare va attribuita al costrutto di scelta; la norma dice che se più
transizioni di una scelta possono essere superati contemporaneamente, esse vengono
effettivamente superate dando luogo all’esecuzione in parallelo dei rami. Ciò è però
sconsigliato e viene demandato all’utente programmatore il compito di stabilire una
prioritàtralesequenzeinparallelo. Con l’apposizionedi un’asterisco incorrispondenza
della divergenza si f isserà automaticamente una priorità crescente delle transizioni da
sinistra verso destra (a meno che non venga esplicitamente fissata con dei numeri sui
Il softwarecheimplementaunarisorsainunaconfigurazioneèdetto ‘‘Target Kernel’’ .
Esso èdisponibile ‘‘off-the-shelf ’’ per WindowsNT, VxWorkseOS-9. Esso può inoltre
essereportato su qualsiasi hardwaregraziead un compilatoreC.
CODICE
Le risorse programmate con il workbench sono compilate per produrre il codice
TIC (Target Indipendent Code), che viene scaricato su una Configurazione per essere
eseguito daun Kernel. Il compilatorepuò ancheprodurre il codice sorgente ‘‘C’’
DEBUG
Sono disponibili strumenti di bebugging di alto livello, incluso un simulatore.
1 THE WORKBENCH (ambientedi lavoro)
40
1.1 THE PROJECT (il progetto)
Il processo di installazionecrea laseguentestrutturadi directory:
Il Progetto viene memorizzato nella directory di � progetto � , con formato MS
Access Database file (PRJLIBRARY.MDB). Come si osserva esiste una cartella per
ogni configurazione e per ognuna di esse una cartella per le risorse; la gerarchia tra
gli elementi di programmazionequindi è rispecchiatanellasrutturadelledirectory.
Si può scegliere il modello mono risorsa oppure multi risorsa che contiene due
Risorse in duedifferenti Configurazioni ConnessedaunareteEthernet. Talemodello è
disponibilesolo nelleversioni del workbench abilitateallagestionedelle reti.
� Root �bin Eseguibiligrp Gruppi Windowsprj Progetti� progetto� Directory individualedi progetto� config. � Una directory per ogni configurazione
hardware� Risorsa� Unadirectory per ogni risorsatpl Modello del Progetto
mono-resource Nomedel Modello� config. � Una directory per ogni configurazionehardware� Risorsa� Unadirectory per ogni risorsa
multi-resource Nomedel Modello� config. � Una directory per ogni configurazionehardware� Risorsa� Unadirectory per ogni risorsa
Tabella6: StrutturaDirectory del progetto
1.2 LINK ARCHITECTURE (architettura dei collegamenti)
La finestra ‘‘Link Architecture’’ visualiza graficamente le Risorse di un Progetto e i
collegamenti di dati tra loro. Questa è lavistadi default per il workbench.
41
figura 2: Workshop : Rappresentazionegrafica del flusso di dati tra leRisorse
Tale finestraèusata per:
� CreareRisorse.� Definire i collegamenti di dati (Bindings) tra leRisorse.� Definire egestire i Gruppi di Variabili.� Creareemanipolare i Programmi.� CreareFunzioni.� CreareBlocchi di Funzioni.� Definire i collegamenti di I/O.
1.3 RESOURCE (Risorsa)
Ogni Risorsa(fig. 3) vienevisualizzata in unadiversa finestraall’ interno della finestra
‘‘Link Architecture’’ . La barra del titolo include il nome e il commento riferito alla
Risorsa, il pulsanteper massimizzarelafinestraeil pulsanteData Link (vedi dopo) per
creareed evidenziaregraficamente i collegamenti di dati tra leRisorse.
42
figura 3: Esempio di Risorsa
L’ambientedi lavoro visualizzaunarappresentazionegraficadei vari componenti di
ogni Risorsa:
� Parametri (Parameters)� Gruppi di Variabili (Variablegroups)� Programmi (Programs)� Funzioni (Functions)� Blocchi Funzionali (Function Blocks)
1.3.1 PARAMETRI
Lavoce ‘Parameters’ consistedi tresottocampi:
� I/O Wiring� Defined Words� User Data
I /O Wir ing (Collegamenti I /O) Consentedi accedereallo strumento ‘ I/O Wiring’ per
selezionarei dispositivi di I/O eper connettereessi con levariabili. E’ lo strumento che
in praticanellanormaèdescritto comepercorso d’accesso per levariabili
43
Defined Words (Dichiarazioni) Consente di apire il Dizionario ed editare le costanti
del progetto.
User Data (Dati Utente) Consente di aprire l’ambiente per editare codice o
dichiarazioni specifiche da inglobare nel progetto e interpretabile del kernel della
macchina target. Questo oggetto potrebbe non apparire (in conformità con il Target
collegato alla Risorsa).
1.3.2 GRUPPO DI VARIABILI
Fornisce un metodo per gestire le variabili ordinandole logicamente all’ interno della
Risorsa. I gruppi di variabili sonomostrati nell’alberodellevariabili (VariablesTree) eil
loro contenuto èdefinito all’ interno dellagrigliadi variabili del Dizionario (Dictionary
VariablesGrid ).
1.3.3 PROGRAMMI
I Programmi sono conosciuti anchecomePOUs(Program Organizaton Unit). LePOUs
Viene inoltre visualizzata una finestra di dialogo con le proprietà di connessione
quando:
� vienecreataunanuovaConnessione,� si faun double-click su unaConnessioneesistente,� selezionando il comando ‘Properties’ dal menu Edit con una connessione
selezionata.
La lista dei parametri dipende dalla Configurazione connessa alla Rete. Essa
potrebbe essere anche vuota. Alcuni parametri sono di sola lettura: per il driver ETCP
(Ethernet), è richiesto il solo indirizzo IP dellaConfigurazione.
1.6 DIZIONARIO (Dictionary)
Il Dizionario (vedi 7) è uno strumento di editing per la dichiarazione delleVar iabili,
dei parametr i delle Funzioni e dei Blocchi Funzionali, dei Tipi Utente e delle
dichiarazioni del Progetto.
48
figura 7: Elenco dellevariabili di programma
I vari componenti sono ordinati con unasortadi gerarchia in un albero, per esempio,
per Risorse o per Tipo. I componenti selezionati nell’albero vengono visualizzati nel
dettaglio in una tabelladatabase formattato, detto Griglia (Grid ).
Esso rappresentauno strumento di editing di variabili molto potenteeversatile, alla
streguadi uncomunedatabaseelettronico per quantoriguardalefunzioni di trattamento
emovimentazionedei dati.
La finestra del Dizionario (Dictionary window) viene visualizzata nell’ambiente di
lavoro. I menù e le barre degli strumenti in tal caso propongono solo le opzioni del
Dizionario (context menu). Laparte sinistradella finestracontiene una vista ad albero
gerarchica delle Variabili, Parametri, Tipi e Definizioni. Ci sono quattro alberi che
possono essere usati per creare e modificare i dati. La parte destra invece mosta la
tabella tipo griglia.
49
I vari rami dell’albero forniscono modi differenti di accesso ai dati trattati dal
Dizionario (rif. Tab. 7)
Top LevelResources
VariableGroup LaGrigliavisualizzasolo levariabili di quel gruppoAny Group
All Variables LaGrigliacontiene tutte levariabili dellaRisorsaGlobal Variables LaGrigliacontiene tutte levariabili globaliPrograms LaGrigliacontiene tutte levariabili locali al ProgrammaFunctions LaGrigliacontiene tutte levariabili locali alla funzione
– i nomi delle Variabili, Array e Strutture non possono essere gli stessi delle
parole riservate
– Validitàe rangedegli Indirizzi
per colonna� Retain : non può essere Input/Output� se il tipo non èStringa, lacolonna ‘‘ ()’’ deveesserevuota� Controllo del f lusso:
– Internal: lacellaWiring deveesserevuota
– Input: lacellaWiring deve iniziarecon %I
– Output: lacellaWiring deve iniziarecon %Q
50
� Controllo degli attributi:
– Può esseresolo ‘‘Read-only’’ per Inputs
– Può esseresolo ‘‘Write’’ o ‘‘Free’’ per Outputs
– Unavariabiledi tipo Inputs non può averevalore iniziale
– Unavariabiledi tipo Retain non può averevalore iniziale
per tutto il database
COLONNA DESCRIZIONE
Name Nome della Variabile: limitato a 128 caratteri, deveconformarsi allo standard IEC
Alias Qualsiasi nome. E’ usato nell’editor LD (Ladder)Group Nomedel gruppo o ’’None’’Type BOOL, DINT, SINT, REAL, TIME, STRING, Array Types,
StructureTypes, Function Blocks( ) Se il tipo è STRING rappresenta la lunghezza della stringa
(max. 255 caratteri)Dimension La dimensione (numero di elementi) di un Array. Per
esempio: [1..3,1..10] rappresenta un Array bidimensionalecontenenteun totaledi 30 elementi
Attribute Una variabile può essere ’’ read-only’’ , ’’write-only’’ oppurepuò essere lettaescritta (’’ free’’ )
Scope Global : La visibilitàdella variabileè estesaa tutte lePOUsdi unaRisorsaCommon : La visibilità della variabile è estesa a tutte lePOUs all’ interno di un Progetto. (N.B. Solo le ’’DefinedWords’’ e levariabili tipizzatepossono averevisibilitàdi tipocommon)Local : La visibilità della variabile è estesa alla sola POUnellaqualeèdichiarata.
Tabella8: Griglia Variabili
� Le funzioni IEC hanno uno e un solo Parametro di uscita, chiamato come la
Funzione� I nomi dei Parametri delleFunzioni edei Blocchi Funzionali non sono duplicati� I Parametri sono ordinati (Input poi Outputs)� I nomi delle Variabili non sono duplicati all’ interno di unaRisorsa� I nomi delle Variabili Locali:
– Non sono duplicati all’ interno di unaPOU
– Non hanno il nomedi unaVariabileGlobale
51
� All’ interno di unaStruttura, un campo non è ripetuto� Il numero massimo di Parametri nelle Funzioni e nei Blocchi Funzionali è
di un Dispositivo di ingresso.OUTPUT : Unavariabiledi output connessaad un canaledioutput di un Dispositivo di uscita.Internal : chenon èconnessaad un dispositivo di I/O. Si puòanchechiamare ’’Memory Variable’’
Init.value Valore che ha la variabile quando il kernel comincial’esecuzione della Risorsa. Esso può essere un valore didefault, un valore definito dall’utente quando la variabile èdichiarata oppure il valore di ’’ retain’’ (mantenuto) che essaavevaquando il kernel èstato fermato l’ultimavolta.
Wiring Cella non editabile : generata dal tool di I/O Wiring. Usa lasintassi dellevariabili direttamente rappresentate
Comment Commenti dell’utente in formato liberoRetain Variabileavalore ritenuto (Yes/No).Address Opzionale. Espresso in Esadecimale nel range da 1 a FFFF.
Liberamente definito per ogni Variabile. Questo indirizzopuò essere usato da un’applicazione esterna per accedere alvaloredellavariablequando la risorsaèeseguitadal kernel.
Tabella9: Griglia Variabili
1.6.1 VALORI INIZIALI
Viene applicato alle sole Variabili. Se non è immesso alcun valore, viene usato 0 (o
FALSE) per default comeprevisto dalla norma.
I valori iniziali per tipo di variabilesono specificati in tabella10
52
TIPO DEFAULT DETTAGLI
BOOL FALSE TRUE o FALSEDINT 0 qualsiasi altro valore interoSINT 0 qualsiasi altro valore intero shortREAL 0.0 qualsiasi altro valore reale f loat (non double). Può essere
inserito il formato scientif ico (1.2E+10)STRING empty qualsiasi set di caratteri contenuti all’ interno degli apici, per
: t#WhXmYsZms or t#Z0 � = W: numero di ore0 � = X: numero di minuti0 � = Y: numero di secondi0 � = Z: numero di millisecondii campi h, m, s o ms non sono richiesti. Se viene immessot#100, esso corrispondea t#100ms.
Array initialization 0 or FALSEStructure initialization 0 or FALSE
Tabella10: Valori Iniziali
1.6.2 GRIGLIA PARAMETRI
La griglia dei parametri definisce l’ interfaccia delle Funzioni e dei Blocchi Funzionali
creati nelleRisorsedel Progetto. Lecolonneper i Parametri sono illustrati in tabella11
COLONNA DETTAGLI
Name NomeParametro : limitato ad un max. di 128 caratteri econformeallo StandardIEC.
Short Name Nomebreveusatonegli editor FBD eLD per lasolavisualizzazione(max. 4car.).Type Tipo : BOOL, DINT, SINT, REAL, TIME, STRING, Array Type, StructureType,
Function Block.( ) Se il tipo èSTRING, ( ) è lasua lunghezza (max. 255 car.).Dimension Esempio : [1..4,1..7] per un Array bidimensionale.Direction Parametro di Input, Output o Local.Comment Commenti dell’utente in formato libero
Tabella11: Parametri
I Parametri sono ordinati all’ interno del database : ‘‘ Input’’ , poi ‘‘Output’’ , e infine
‘‘Local’’ . Le funzioni hanno solo un Parametro di uscita; esso deve essere un tipo
semplice (per es. no Arrays o Structures). Le istanze dei Blocchi di Funzioni possono
53
essere definiti solo come Parametri Locali di Blocchi di Funzioni. Per chiamare un
Blocco Funzionalein un altro Blocco Funzionale(nesting), ènecessario crearel’ istanza
del Blocco chiamato comeParametro Localedel Blocco chiamante.
1.6.3 GRIGLIA TIPI STRUTTURATI
Vieneusataper creare tipi complessi chesaranno poi disponibili per ledichiarazioni di
variabili, e tali nuovi tipi saranno disponibili poi nellacasella ’Type’ di tutte le griglie.
Arrays:
COLONNA DETTAGLI
NameElt. Type Tipo dell’elemento dell’Array : BOOL, DINT, SINT, REAL, TIME, STRING,
User Arrays, Structures( ) Se il tipo èSTRING, ( ) è lasua lunghezza (max. 255 car.).Dimension Example: [1..10] per un Array monodimensionale, [1..4,1..7] per un Array
bidimensionale.Comment Commenti dell’utente in formato libero
Tabella12: Array
Structures:COLONNA DETTAGLI
Name Nome dell’Elemento : limitato ad un max. di 128 caratteri e conforme alloStandard IEC.
Elt. Type BOOL, DINT, SINT, REAL, TIME, STRING, User Arrays, Structures.( ) Se il tipo èSTRING, ( ) è lasua lunghezza (max. 255 car.).Comment Commenti dell’utente in formato libero
Tabella13: Strutture
Per creare una struttura con un elemento dimensionale, prima si crea un Array e
poi una struttura con un elemento del tipo ! nome Array " . I tipi r icorsivi non sono
ammessi (per esempio: un campo di ‘str1’ non può esseredi tipo ‘str1’ ).
54
1.6.4 GRIGLIA COSTANTI
Lecolonneper lecostanti (defined word) sono espressenella tab.14
COLONNA DETTAGLIWord Nome usato nei files sorgente ST : il primo carattere deve essere una lettera,
seguito da lettere, cifreo underscore ( ’_’ )Equivalent Unastringacompatibilecon lasintassi ST, cherimpiazzalaword definitadurante
lacompilazione. Per esempio: Word = PI, Equivalent = 3.14159Comment Commenti dell’utente in formato libero
Tabella14: Costanti
1.7 I /O WIRING SECTION (sezionecollegamenti I /O)
Come ultima cosa accenniamo alle potenzialità di gestire collegamenti remoti in rete
di ISaGRAF per completareunaprimapanoramicasullecaratteristichedel workbench.
L’ambientedi lavoro metteadisposizioneuno strumento completo simileal Dictionary
giàpresentato nellasezione precedente.
La parte sinistra del workspace di I/O wiring è costituito da una vista ad albero
gerarchico dei dispositivi di I/O che sono stati definiti. La parte destra visualizza una
Essadeve essere collegata in particolaread un canaledi un dispositivo di I/O.
Il ‘wiring I/O’ definisce i collegamenti tra le variabili del progetto e i canali dei
Dispositivi esistenti su un sistema ‘Target’ .
Quando viene aggiunto un Dispositivo di I/O si può usare la rappresentazione delle
variabili in forma diretta (%IX1.1) per accedere al suo valore. Si possono inoltre
connettere Variabili che sono già state dichiarate nel Dizionario e usare i nomi di tali
variabili per accedereai valori di I/O remoto.
Il Dispositivo di accesso remoto può essere classificato in una delle due categorie:
‘complex’ o ‘simple’ ; tali voci corrispondono rispettivamente ad un elemento che
raggruppa più dispositivi oppure ad un elemento che raggruppa più canali dello stesso
tipo (Bool, DINT, SINT, REAL, STRING) e che hanno la stessa Direzione (INPUT,
OUTPUT).
L’ implementazione di un driver di un dispositivo di I/O ’complex’ equivale
all’ implementazione di ciascuno dei Driver dei singoli Dispositivi di cui è
composto. Vengono attribuiti a tale Dispositivo i parametri OEM (Original Equipment
Manufacturer - ‘‘ impostazioni di fabbrica’’ )
Per i Dipositivi ‘simple’ è disponibile la ‘connessione’ di un Array se tutti gli
elementi dello stesso appartengono a canali contigui e il tipo dell’Array deve essere lo
stesso del Dispositivo. Anche le Strutture possono essereconnesse. Il driver I/O viene
scritto in codice ‘‘C’’ e implementa appunto l’ interfaccia tra il Kernel e i Dispositivi
hardware. Essopuòrisiederenel Kernel oppurefuori inunaDLL (per il Target Windows
NT).
56
2 THE TARGET
Il pacchetto ‘Target’ permettedi:
# Eseguire i progetti in modo Real Time# IntegrarenuoveFunzioni ‘‘C’’ eBlocchi Funzionali
Laparola ‘‘Target’’ hadiversi significati:
# La piattaformaHardwaresullaquale il Kernel manda in esecuzione leRisorsedi
un Progetto. Laparolaappropriata in questo caso èperò Configurazione.# Il Kernel stesso della macchina virtuale. Il Kernel è il software che esegue una
Risorsadi un Progetto. Su ogni Configurazionepossono risiederepiù Kernels.
La parola ‘‘Target’’ appare anche nel workbench: si può selezionare e attribuire un
I programmi sequenziali principali devono essere descritti con il linguaggio SFC
o FC, mentre i programmi ciclici non possono essere implementati in SFC nè in FC.
Qualsiasi Programma SFC può avere uno o più figli di tipo SFC. Ogni programma FC
può richiamareuno o più sub-programmi FC.
59
LeFunzioni e i Blocchi Funzionali non possono esseredescritti con i linguaggi SFC
o FC. Essi possono essererichiamati però dalleazioni o dallecondizioni dei Programmi
SFC eFC.
I Programmi collocati all’ inizio del ciclo (prima dei Programmi sequenziali) sono
tipicamente usati per descrivere azioni preliminari su un dispositivo di ingresso. I
Programmi collocati allafinedel ciclo (dopo i Programmi sequenziali) sonousualmente
implementati per garantire livelli di sicurezza per le variabili utilizzate dai Programi
sequenziali, primache i loro valori vengano trasmessi ai dispositivi di output.
CHILD SFC PROGRAMS
Ogni Programma SFC può controllare altri Programmi SFC di livello più basso
detti Child-SFC. Esso è un Programma parallelo che può essere iniziato (star ted),
chiuso (killed), bloccato o congelato (frozen) oppure fatto ripartire dopo essere stato
bloccato (restar ted) dal suo programma padre. Essi devono essere descritti entrambi
in linguaggio SFC. Un Programmachild SFC può averedellevariabili locali.
FC SUB-PROGRAM
Ogni Programma FC può richiamare uno o più Programmi FC. L’esecuzione dei
sotto-programmi FC viene pilotata dall’FC padre, la cui avanzata viene sospesa fino
al terminedel programmafiglio.
FUNCTIONS
L’esecuzione di una Funzione è comandata dal programma padre. Anche qui
l’esecuzione del programma padre viene sospesa. Le Funzioni possono essere
richiamate da qualsiasi programma in qualsiasi sezione. Una funzione può avere
60
variabili locali eper descriverlepuò essereusato un qualsiasi linguaggio eccetto SFC e
FC.
ATTENZIONE:
& Il sistema non supporta la ricorsività delle chiamate. Verrà generato un errore in
run-timesesi verif ica taleevenienza.& Una Funzionenon può memorizzare il valoredellesuevariabili locali : essanon
viene istanziataequindi non può richiamarenessun blocco funzionale.
L’ interfaccia di una Funzione deve essere esplicitamente definita, con un tipo e un
unico nome per ognuno dei suoi parametri di ingresso o per il parametro di ritorno (di
uscita). Per garantirelaconvenzionedel linguaggioST, il parametrodi uscitadeveavere
lo stesso nome della funzioneeci può essereun unico parametro di uscita.
Ecco comeassegnare il valoreal parametro di uscitanei differenti linguaggi:
& ST: vieneassegnato attraverso il suo nome(ugualeaquello della funzione):
FunctionName:= ' expression( ;& IL: il valore del parametro è quello del risultato corrente (registro IL) alla fine
dellasequenzadi istruzioni& FBD: vieneassegnato attraverso il nomedel blocco funzionale& LD: usando una bobinacon il nome del parametro di ritorno
FUNCTION BLOCK
Essi possonousarei seguenti linguaggi: LD, FBD, ST oIL. Vengonoinoltreistanziati
cioè le variabili locali di un Blocco Funzionale vengono copiate per ogni istanziazione
per cui conservano il loro valore tra un ciclo ed un altro quando vengono richiamati
all’ interno di un programma.
61
L’ interfacciadi un Blocco Funzionaledeveesseereesplicitamentedichiarata, con un
tipo eun unico nomeper ognuno dei suoi parametri di ingresso edi uscita. A differenza
delleFunzioni, è possibileaverepiù di un parametro di uscita.
L’assegnazione dei valori alle variabili di uscita è fatta in maniera analoga a quella
delleFunzioni.
ATTENZIONE
Quando si crea un loop con i blocchi funzionali è necessario usare variabili locali
primadellachiusuradel ciclo.
EXECUTION RULES (regoledi evoluzione)
Il sistema èSincrono. Tutte leoperazioni sono scanditedaun clock.
figura 9: Ciclo del Target
Questo sistemarendepossibile:
) garantireche levariabili mantengano lo stesso valoreall’ interno del ciclo
62
* garantirecheun dispositivo di uscitanon vengaaggiornato per più di unavolta in
un ciclo* lavorare in sicurezzasullestessevariabili globali tradifferenti programmi* stimareecontrollare il tempo di rispostadell’applicazione intera.
4 LINGUAGGIO SFC
L’SFC (Sequential Function Chart) è il linguaggio grafico usato per descrivere
operazioni sequenziali. Esso è composto da una serie di ben definiti passi (Steps),
collegati da transizioni (Transitions). Ad ogni transizione è associata una condizione
booleana. Una o più azioni invece sono associate ai passi. Le Condizioni e le Azioni
sono esplicitateattraverso altri linguaggi (ST, IL o LD). DalleCondizioni edalleAzioni
possono essere richiamateFunzioni eBlocchi Funzionali.
Le regoledi sintassi dell’SFC sono quellestandard cheprevede lanorma:
* I Programmi SFC devono averealmeno una fase iniziale.* Un passo non può essereseguito daun altro passo.* Una transizionenon può essereseguita daun altra transizione.
Gli elementi visualizzati e i parametri dell’SFC sono:
* In esecuzione, un gettone (Token) indicache il passo èattivo* StepName.x : attivitàdel passo (valoreBooleano)* StepName.t : duratadall’attivazionedel passo (volredi tipo time)
Possono essere usati simboli di salto (Jump) per indicare la connessione la una
transizione a un passo, omettendo di tracciare l’arco orientato. Il salto si deve riferire
al nomedel passo destinazione.
63
Per quantoriguardaleconvergenzeeledivergenzeesseseguonofedelmentelanorma
ecometaledettaaproposito delledivergenzesingole(scelta), non sono esplicitamente
esclusive, comedel resto prevede lanorma. Lamutuaesclusivitàviene indicatacon un
asterisco in corrispondenzadelladivergenzastessa.
MACRO STEPS(MarcoFase)
E’ un unica rappresentazione di un gruppo di passi e transizioni. Essa deve iniziare
con un passo e terminare con una transizione. La stessa macrofase non può essere
richiamataper più di una voltanel programma.
4.1 AZIONI COLLEGATE AI PASSI
La descrizione dettagliata delle Azioni eseguite durante l’attività del passo viene fatta
usando il linguaggio letterale proprio dell’SFC (le istruzioni possibili) oppure un
qualsiasi altro linguaggio (ST o LD).
I tipi basilari di azioni sono:
+ Azioni Booleanecon qualif icatoredi tipo Set, Reset o Non-Stored.+ Lista di istruzioni programmata in ST, LD o IL con qualif icatore Pulse o Non-
Stored.+ Azioni SFC (gestionedi SFC children) con qualificatori Set, Reset o Non-Stored.
Più Azioni possono inoltreessereassociateallo stesso passo.
Di seguito vengono descritti i tipi di azioni comuni:
64
4.1.1 BOOLEAN
Un azione boolana consiste di un’assegnazione di un valore ad una variabile booleana
in corrispondenza dell’attivazione del passo. Essa può essere una variabile di uscita o
di memoria.
I qualificatori hanno il signif icato descritto dallanorma.
4.1.2 PULSE (impulsiva)
E’ una lista di istruzioni che viene eseguita una sola volta all’attivazione del passo
(qualificatore P1) oppure alla deattivazione del passo (qualif icatore P0). Le istruzioni
sono scritte in linguaggio ST, IL o LD.
4.1.3 NON STORED (non memor izzata)
Unaazionenon-stored (normale) èuna listadi istruzioni in linguaggio ST, IL o LD che
sono eseguite ciclicamente durante il tempo in cui il passo è attivo. Il qualif icatore è
‘N’ .
4.1.4 SFC ACTIONS(azioni SFC)
Un’azione SFC è un SFC-child, lanciato o fermato in corrispondenza dell’attivazione
e della disattivazione del segnale di attività del passo. A seconda del qualif icatore
dell’azioneabbiamo:
, N : L’SFC child viene lanciato con l’attivazione del passo e interrotto con la sua
deattivazione., S: L’SFC child viene solo lanciato all’attivazione del passo; prosegue come task
indipendentedaquesto punto in poi., R : L’SFC child viene interrotto con l’attivaionedel passo.
65
4.1.5 IL (lista istruzioni)
Le azioni corrispondenti a più operazioni possono essere implementate usando il
linguaggio ST, IL o LD. Tali azioni possono avere il qualif icatoreN, P0 o P1.
4.1.6 CALLING FUNCT. OR FUNCT. BLOCK
Possono inoltre essere richiamate direttamente Funzioni o Blocchi Funzionali scritti in
linguaggio ST, IL, LD o FBD oltre che in linguaggio ‘‘C’’ , basate sul linguaggio usato
negli Action Block.
4.2 TRANSITIONS(transizioni)
Lacondizionedi solito èespressanel linguaggio ST o LD. Questo èil cosiddetto livello
2 della transizione. I modi per programmareunacondizionesono:
- Programmata in ST, LD o IL- Richiamando una funzionevalutando il valore restituito.
ATTENZIONE:
- Quando nessunacondizionevieneassociataallatransizionevieneimplicitamente
assegnato il valoreTRUE.- E’ raccomandabile non richiamare un Blocco Funzionale in una condizione SFC
perchè:
1) Un FB dovrebbe essere richiamato ad ogni ciclo, tipicamente in un programma
ciclico. Per esempio i blocchi contatore fanno un operazione di incremento ad ogni
ciclo, i blocchi trigger hanno bisogno di memorizzareun valorebooleano ad ogni ciclo
per testare i fronti di salitao di discesa .
66
2) La condizione viene valutata solo quando tutti i passi precedenti la transizione
sono attivi (non ad ogni ciclo)
4.3 EVOLUZIONE DINAMICA
Lecinque regoledi evoluzionedell’SFC sono:
. SITUAZIONE INIZIALE : E’ caratterizzata dai passi iniziali che sono, per
definizione, attivi all’ inizio del programma; cenedeveesserealmeno uno in ogni
programma. SUPERAMENTO DELLA TRANSIZIONE : Si dicechelatransizioneèabilitata
(al suo superamento) quando tutti i passi che laprecedono immediatamentesono
attivi. Essa può essere superata se è abilitata e se la condizione ad essa associata
èvera.. CAMBIAMENTO DI STATO DEI PASSI : Il superamento della transizione
porta nello stato attivo tutti i passi immediatamente seguenti la transizione e
contemporaneamente vengono disattivati tutti i passi a monte della transizione
stessa.. SUPERAMENTO SIMULTANEO DI TRANSIZIONI : Tutte le transizioni che
sono superabili vengono superate simultaneamente come pure l’attivazione e la
disattivazionedei passi; laprioritàper questi ultimi è per la loro attivazione.
4.4 HIERARCHY (gerarchia)
I Programmi SFC sono organizzati in gerarchie ad albero e ogni SFC può controllare i
suoi SFC figli.
Le regoledi basederivanti da tali gerarchiesono:
. Gli SFC chenon hanno padresono detti Programmi SFC ‘‘main’’. I Programmi SFCMainSFCsonoattivati dal sistemaquando l’applicazioneviene
lanciata. Un Programmapuò averepiù Programmi figli
67
/ Un Programmafiglio non può averepiù di un padre/ Un Programmafiglio può esserecontrollato solo dal suo padre/ Un Programmanon può controllareun figlio di un suo figlio
5 COMPATIBILITA’ CON LA NORMA
5.1 PROGRAMMAZIONE SFC
Si elencaoraunaseriedi non-conformità riscontrate nellaprogrammazioneSFC:
Non sono disponibili per le azioni tutti i qualificator i previsti dalla norma; in
particolarevengono implementati i qualif icatori:
/ N, S, R conformi/ P0 e P1 estensioni del qualif icatore P che agiscono rispettivamente sui fronti di
salitaedi discesadel segnale
inoltre a seconda dei linguaggi adoperati per descrivere le azioni associate ai passi
sono disonibili alcuni soltanto dei suddetti qualif icatori; in particolare:
/ AzioneBooleana : qualificatori disponibili N, S, R/ Linguaggi LD, IL, ST : qualificatori disponibili N, P0 eP1/ Azioni SFC : N, S, R
Notiamoesplicitamentecheil qualif icatoreS(set) per il secondopuntoèequivalente,
dal punto di vista del comportamento, al qualif icatore N (non-stored) per quanto detta
la Norma. Per le Azioni SFC, essi servono a controllare l’evoluzione di un altro SFC
(child). ISaGRAF metteadisposizioneanchedelle istruzioni ST per il controllo di altri
SFC (GSTART : equivalente a ‘S’ ; GKILL equivalente a ‘R’ ; GFREEZE : disabilita
tutte le fasi del’SFC pilotato memorizzando il suo stato in modo da poterlo ripristinare
un qualif icatore temporale (L, D, SL, SD, o DS). Bisogna inserire il numero del
timer (0-999) chedeveessereusato per questa azionedel passo.9 Risoluzionedel Timer (Timer Resolution) : può essere10ms o 1s.9 Presettaggio Timer (Timer Preset) : valore iniziale del timer.9 Timer Address : indica l’ indirizzo fisico del timer. E’ un campo read-only.9 Timer del passo (Step Timer) : serve a monitorare il tempo trascorso
dall’attivazione di ogni passo e quindi a capire quanto velocemente si muove
il nostro processo. Si possono far partire anche altri programmi basati su una
combinazione dei passi attivi; specif icando quali passi si vogliono monitorare si
possono usare programmi ladder basati su tali timer per controllare il f lusso del
programma. Si possono monitorare fino a 1000 passi1.
:Questo dipendeessenzialmentedal fatto checi sono adisposizionedel PLC 1000 timer complessivamente
81
4.6 Forzareuna transizione
Solo per processori PLC-5 Enhanced. E’ possibile, una volta abilitata la possibilità
di forzamento, forzare il superamento di una transizione oppure bloccarla, lavorando
online con il PLC.
4.7 GOTO
Permettedi muoversi all’ internodel programmasaltando interesezioni di programma, e
riprendere l’esecuzione in un dato punto. Talepunto specif ico è indicato dauna‘ label’ .
4.8 LABEL
Specifica il punto nel quale dovrà riprendere l’esecuzione di un programma dopo un
salto con GOTO. Si possono inserirecomeetichette i numeri da001 a 250.
4.9 MacroFase (SFC macro)
Una macro è una porzione di un SFC condensata in un unico passo. Può contenere un
intero ramo o una coppia passo/transizione. Viene visualizzata con un rettangolo con
unadoppia lineasui bordi verticali. Con un doppio click vieneespanso.
5 Compatibilità con la norma
Il softwareRSLogix 5èprogettatoper controllareegestirei PLCdellaAllenBradley per
cui lesuefunzionalitàsonostrettamentecorrelateaquelledel processorechedeveessere
gestito. Ad esempio, vengono implementati soltanto i linguaggi di programmazione
SFC e Ladder Diagram e, quando il processore PLC lo permette, il linguaggio Testo
82
Strutturato. Comunque per quanto riguarda tali linguaggi essi non r ispondono agli
standard della norma ma piuttosto alle istruzioni effettivamente implementate su
ogni PLC.
Se si sceglie invece come piattaforma quella SoftLogix 5 basata su controllo real-
che verranno memorizzate su file o caricate le informazioni relative ad ognuno degli
SFC checompongono il progetto.
La seconda coppia di pulsanti permette rispettivamente di caricare o salvare su
disco un solo SFC, selezionato con il Tab corrispondente evidenziato. Ciò significa
che se si carica un file SFC esso prenderà il posto corrispondente al Tab selezionato :
ognunodegli elementi checompongonol’SFCsarànumeratodi conseguenzaper evitare
duplicazioni dei nomi tragli elementi dei vari SFC checompongono il progetto.
L’ultima coppia di pulsanti permette rispettivamente di Importare (Imp) o Esportare
(Exp) un progetto intero in MetaLinguaggio2.
3.2.3 Syntax Check
Proseguendo con i pulsanti troviamo il pulsante di Check (Chk) che serve a
produrre un controllo sull’SFC corrente descrivendone gli eventuali errori di sintassi
o producendo i cosiddetti ‘avvertimenti’ (warnings).
Gli errori chesaranno prodotti evidenzieranno :
> Oggetti f lottanti ossianon agganciati aniente> Transizioni con un link ‘‘appeso’’> Ogetti di convergenzaedivergenzacon qualche link non agganciato> Ambiguità di f lusso per la direzione degli archi orientati : per esempio entrambi
gli archi entranti in un passo.
?Si rimandaallasezionededicataal MetaLinguaggio per approfondimenti.
97
Gli avvertimenti o warningssono invece :
@ per una fase : uno dei link non èagganciato
Un esempio di output è dato nella fig. 15
figura 15: Output Check
3.2.4 Edit Tools
Attraverso questi 9 pulsanti è possibile inserire qualsiasi elemento all’ interno del
nostro SFC. In sequenza i pulsanti sono associati ai seguenti oggetti :
@ Fase Iniziale (initial step)@ Fase (Step)@ Transizione (Transition)@ Arco Orientato (Oriented Arc)@ Divergenza (Divergence)@ Sincronizzazione (Syncro)@ Selezione (Select)@ Convergenza (Convergence)@ Tool di Selezione (Select Tool)
98
Scegliendo uno di questi pulsanti (trannel’ultimo) il programmaconsentedi inserire
l’oggetto corrispondente e di ‘ linkarlo’ direttamente qualora la sua posizione risulti
compatibile con le regole sintattiche di un SFC; tale operazione viene segnalata
acusticamente con un beep e visivamente con una croce (cross) in corrispondenza del
punto in cui verràcreato l’arco. L’arco vieneautomaticamenteorientato dall’alto verso
il basso secondo il normale f lusso del programma.
Lo strumento di selezione consente appunto di selezionare gli oggetti (direttamante
oppure tramite ‘net-selection’ - o ‘a rete’ ), di cancellare (tramite il tasto ‘CANC’)
e di spostare gli oggetti selezionati (colorati in rosso) trascinandoli con il mouse.
Osserviamo che durante l’operazione di spostamento degli oggetti sullo schermo,
essi non vengono collegati con altr i oggetti, anche se le loro posizioni r isultano
compatibili con leregolesintattiche: bisognaprovvedereaduncollegamentomanuale
attraverso lo strumento dell’arco orientato.
3.2.5 Visualizzazionedettagliata
Il pulsante successivo fa da ‘ toggle’ tra la visualizzazione dettagliata e non.
Nella visualizzazione dettagliata accanto ad ogni passo compare un rettangolo con il
qualif icatore d’azione e il nome dell’azione associata al passo, mentre accanto ad ogni
transizionevienevisualizzata lacondizione di superamento.
3.2.6 Impostazionedimensioni documento
99
Attraverso questo pulsante è possibile specificare le dimensioni del documento (in
mm) relativo all’SFC selezionato. Compare una finestra di dialogo che consente di
immettere le nuove dimensioni oppure scegliere, tramite il pulsante di ‘‘Auto Size’’ di
inserireledimensioni del documentoautomaticamenteinmodocheesso racchiudatutto
l’SFC.
figura 16: Finestra di proprietà del documento
3.2.7 Refresh
L’ultimo pulsante consente di fare il refresh dello schermo qualora, in fase di
scorrimento ad esempio, laqualitàdel grafico vengadeterioratadaparticolari mancanti
o non correttamenteaggiornati.
3.3 Menù
figura 17: Menù
Vengono orasommariamentedescritte levoci del menù
100
3.3.1 File
Sono presenti i comandi di salvataggio e caricamento degli SFC o dei progetti e i
comandi di stampa, anteprima di stampa e di setup della pagina in fase di stampa. Tali
In fig. 18 è rappresentata la finestradi dialogo per il passo.
In essasi evidenziano i seguenti campi :
A Step Number : E’ possibilemodificare il nomedel passo immettendo un numero
compreso tra0 e99.A Initial : Casella a spunta (checkbox) che indica se la fase deve essere una fase
inizialeper l’SFCA Action Name: Il nomesimbolico associato all’azionedel passo
102
figura 18: Finestra di proprietà per il passo
B Action Qualif ier : Con unacasella ‘ listaacaduta’ (drop list) èpossibilescegliere
il qualifiatored’azione legato all’azionestessadel passoB Timeduration : Indica, in formatostandardIEC1131-3, il tempoassociatoal passo
eha senso qualora il qualif icatored’azionesiaun qualif icatore temporaleB Set Timer : Il pulsante fa apparire un’altra finestra di dialogo che consente di
immettere la variabile temporale di cui al punto precedente. Essa si compone
dei campi giorni (days), ore (hours), minuti (minutes), secondi (seconds) e
millisecondi (milliseconds), ed è rappresentata in fig 19
figura 19: Finestra di dialogo per il settaggio del tempo
3.4.2 Transizione
La finestra di dialogo per la transizione (fig. 20) è essenzialmente costituita da una
caselladi edit (editbox) in formato libero. Lavalutazionesintatticadellacondizionedi
103
figura 20: Finestra di proprietà per la transizione
superamento non viene in alcun modo analizzata rimandando ai tools che riceveranno
in ingresso il MetaLinguaggio tale onere.
3.4.3 Oggetti di convergenza edivergenza (multilink)
figura 21: Finestra di proprietà per gli oggetti multilink
Lafinestradi proprietà(fig. 21) ècaratterizzatadaduecampi numerici; il primo indica
il numerodi link paralleli mentreil secondo lospazio (inunità2*griglia) trai link stessi.
3.5 Stampa
Particolare cura è stata posta alla sezione di stampa. Attraverso il comando di ‘Page
Setup’ è possibile dividere il documento su più pagine. Con riferimento alla figura
22 si può osservare il controllo a slitta con il quale si possono scalare le dimensioni
del documento ingrandendolo fino a 3 volte o riducendolo al 10% della dimensione
originale. A seconda poi delle dimensioni della pagina settate tramite i parametri della
stampante, vengono calcolati il numero di paginedastampareper produrreunastampa
104
figura 22: Finestra di PageSetup
a‘porzioni’ in modo dapoter ricostruire l’ intero documento ravvicinando i singoli fogli
stampati.
Viene presentato anche un preview di come il documento verrà suddiviso (splitted)
tra le pagine; nell’esempio il documento di figura (di dimensioni A4) viene ingrandito
del doppio e suddiviso su 6 pagineA4 orizzontali.
E’ possibile inoltre cambiare direttamente da questa finestra le impostazioni della
stampante e del foglio di carta. Prima della stampa vera e propria è possibile anche
vedere unaanteprimadi stampaselezionando ‘‘Print Preview’’ dal menù File.
3.6 Meta Linguaggio
La necessità di poter usare l’editor come strumento al quale appoggiare altri tools
di sviluppo ha portato alla creazione di un algoritmo che traducesse l’SFC editatato
graficamente in un linguaggio testuale semplice e in corrispondenza ‘uno a uno’ con
l’SFCoriginale. Il programma, comegiàdetto, creaun fileconestensione.mlf editabile
105
conqualsiasi editor di testo. Lapossibilitàdi importareunfiledel genereconsenteanche
di poter scrivere in via testuale l’SFC edi editarlo poi graficamente.
N.B. Per i f ile che devono essere importati c’è un’unica ma importante limitazione
: la fase iniziale deve essere la numero 1 (Sx01) e non deve essere collegata ai link
paralleli di un oggetto MultiLink. Ciò per un corretto funzionamento dell’algoritmo di
posizionamento degli oggetti grafici sullo schermo.
3.6.1 Sintassi
Lasintassi del MetaLinguaggioèstata‘presainprestito’ , conalcunepiccolemodifiche,
dallaNorma IEC1131-3.
Segueunadescrizione delleparolechiaveche identificano un progetto:
Per l’ intero progetto BEGI N_PROJECT; . . . END_PROJECT;
Per ogni SFC : SFC C sf c_numD : C sf c_name D ; . . . END_SFC;
C sf c_numD identif ica il numero dell’SFC
C sf c_name D identifica il nomedell’SFC
Per ogni passo:
STEP C st ep_name D : C act i on_name D ( C qual i f i er , [ t i me] D ) ;
END_STEP;
dove:
C st ep_name D identif ica il nomedel passo
C act i on_name D identifica il nomedell’azioneassociataal passo
C qual i f i er D identif ica il qualif icatored’azione
106
[ t i me] identif ica il valore della variabile di tipo tempo legata ai qualif icatori
temporali
Mentreper ogni Transizione lasintassi è :
TRANSI TI ON
E t r ans_name F FROM ( E st ep_name[ , st ep_name, [ . . . ] ] F ) TO
( E st ep_name[ , st ep_name, [ . . . ] ] F ) : = E bool ean_condi t i on F ;
dove:
E t r ans_name F identif ica il nomedella transizione
E bool ean_condi t i on F identif icalacondizionebooleanadi superamento della
transizione (Default = TRUE)
107
4 Documentazione interna del programma
Comesi èdetto il programmaèstatoscritto inMicrosoft Visual C++ equindi falargouso
delleMFC di Windows. Sono state implementate25 classi al finedi renderemodulare
ecomprensibile il programma, nonchè facilmenteeditabile.
Diciamo innanzitutto che è stata sfruttata l’opportunità del Visual C++ di usare
l’ infrastruttura Documento-Vista, che facilita le operazioni di ‘collegamento’ tra i
dati (gli oggetti dell’SFC) e la visualizzazione degli stessi sul video, nonchè la loro
derivano a loro volta dalla classe base CDrawObj. Teoricamente in tal modo non c’è
limitazione al numero di oggetti implementabili (a patto di non esaurire la memoria!).
Tali oggetti sono individuabili attraverso i loro puntatori, memorizzati all’ interno di una
108
listadinamicaper ogni SFC. Per ogni SFC quindi esisteuna listadinamicache faparte
asuavoltadi una listadi listeper tenere in conto tutti gli SFC del progetto.
Nella tab. 16 si haun riassunto dellestrutturedati globali del programma:Var iabile Tipo Descr izione
GlobObjListMap CMapWordToPtr lista (con chiave) di puntatori a liste del tipoCDrawObjList
pObjList CDrawObjList* puntatore alla lista dell’SFC correntementevisualizzato
CDrawObjList CTypedPtrList lista ’safe handle’ di puntatori agli oggetti (classebase)
ActiveSFC int Contiene il numero dell’SFC correntementevisualizzato
names Array of String Contiene i nomi simbolici degli SFC
Tabella16: Variabili Gloali
Notiamo esplicitamente che i tipi ‘CMapWordToPtr’ e ‘CTypedPtrList’ sono
predefiniti nelleMFC 4.2 di Windows.
E’ interessante ora vedere in tab. 17 quali sono le variabili membro comuni di tali
oggetti per capirecomeessi vengono gestiti ememorizzati.Var iabile Tipo Descr izione
m_position CPoint Contiene la posizione logica del centrodell’oggetto
m_rect CRect per la tecnica dei rettangli invalidanti, contiene loshapedell’oggetto
m_Type enum ObjType il tipo di oggetto (ObjType è un insieme diidentif icatori)
m_Lower[MAX] Array di punt. aCDrawObj i link agli oggetti agganciati verso il bassom_Upper[MAX] Array di punt. aCDrawObj i link agli oggetti agganciati verso l’alton_SFC int il numero di SFC al quale ’oggetto appartienem_absolute int indirizzo assoluto (serveper ricostruire i link nelle
operazioni di I/O)
Tabella17: Variabili Membro di CDrawObj
Ognuno degli oggetti derivati da tale classe ha eventualmente poi altre variabili
membro per gestirequalchecaratteristicachegli èpropria, ad esempio il nomehasenso
109
per il passoelatransizionemanonper l’arcooper l’oggettoMultiLink; per quest’ultimo
invecebisognaprevedereunavariabilechecontenga il numero di rami, ecc...
4.2 Classi
Leclassi più importanti intornoallequali ruotatuttal’ infrastrutturadel programmasono
: GCSFCVi ew - Gest i one del l ’ ar ea di l avor o
GCSFCDoc - Gest i one dat i del Document o e oper azi oni di I / O
GCMai nFr ame - Gest i one del l a f i nest r a pr i nci pal e
Lealtreclassi con le loro descrizioni sono :
Classi chegestiscono gli oggetti :GCDr awObj - Cl asse base per gl i ogget t i di segnabi l i da cui der i vano :
– CAr cObj - St r ut t ur a degl i ar chi or i ent at i
– CPhaseObj - St r ut t ur a del l ’ ogget t o passo
– CTr ansObj - St r ut t ur a del l ’ ogget t o t r ansi z i one
– CMul t i Obj - St r ut t ur a degl i ogget t i Mul t i Li nkGCAr cTool - Gest i sce l e oper azi oni sugl i ar chi or i ent at i
GCPhaseTool - Gest i sce l e oper azi oni sul l ’ ogget t o Passo
GCTr ansTool - Gest i sce l e oper azi oni sul l ’ ogget t o Tr ansi zi one
GCMul t i Tool - Gest i sce l e oper azi oni sugl i ogget t i Mul t i Li nk
GCSel ect Tool - Gest i sce l e oper azi oni del l o st r ument o di Sel ezi one
Classi per i Fogli di Dialogo e Proprietà :GCAbout Dl g - Di al ogo per l a f i nest r a del l e i nf or r mazi oni sul pr ogr amma
GCSFCDl g - Di al ogo per l ’ i mmi ssi one del nome del l ’ SFC
GCAct i onDl g - Di al ogo per l e pr opr i et à del passo
GCTi meDl g - Di al ogo per i nser i r e l a var i abi l e di t i po t empo
GCTr ansDl g - Di al ogo per l e pr opr i et à del l a t r ansi z i one
GCMul t i Dl g - Di al ogo per l e pr opr i et à degl i ogget t i Mul t i Li nk
GCDocPageDl g - Di al ogo per l ’ i mmi ssi one del l e di mensi oni del document o
GCCheckDl g - Fi nest r a di out put per i l check si nt at t i co
GCPageSpl i t Dl g - Di al ogo per i l Set up di Pagi na e l o Spl i t del Document osu pi ù pagi ne
Classi ausiliarieGCSFCApp - Cr eat a dal sof t war e di svi l uppo, cont i ene l e i ni z i al i zzazi onidel l ’ appl i cazi one
110
H CGr aph - Cont i ene l e f unzi oni membr o e l e st r ut t ur e dat i per t r asf or mar ei l f i l e ml f i n un gr af o or i ent at oH CTi mer - St r ut t ur a dat i e f unzi oni necessar i e per l a gest i one del l evar i abi l i t empor al i
Andiamo ora ad analizzare le classi più importanti e quelle che contengono i più
interessanti spunti per una rif lessionesullaprogrammazione.
4.2.1 CDrawObj
Vengono implementate diverse funzioni virtuali che, come ben noto, consentono di
usare lo stesso formalismo sia per gli oggetti di una classe (base) e sia per tutti quelli
derivati dataleclasse; inpraticatali funzioni sonorichiamatequandosi usaunpuntatore
alla classe base per individuare oggetti della classe derivata, consentendo di applicare
la specif ica funzione dichiarata in quest’ultima. Questo è il caso proprio degli oggetti
‘visualizzabili’ del nostro SFC che sono tutti stati fatti derivare da questa classe.
Illustriamo ora il comportamento delle funzioni virtuali implementate atteso che ciò
cheverràdetto per la classebasevaleanche per leclassi derivate:
Funzioni di disegno :
H vir tual void DrawI tem(CSFCView* pView, CDC* pDC)
condizionedi superamento per l’oggetto transizione)
I void MoveTo(Cpoint position)
Aggiorna la posizione logica dell’oggetto e le coordinate del rettangolo
invalidante
I void DrawCircle(CPoint center, int radius, CDC* pDC)
Disegna un cerchietto cheservead evidenziare laconnessione traoggetti
I void Invalidate(CSFCView *pView)
Aggiungealla regioneda invalidare lo shapedell’oggetto.
Funzioni di Gestione
I vir tual int HitTest(CPoint point)
Restituisce un intero che consente di capire se il punto (in coordinate logiche)
passato alla funzione si trova dentro l’oggetto, su uno dei link (e quale) o fuori
dell’oggetto
I vir tual void SelectI tem(CSFCView* pView)J
Teoriadei rettangoli invalidanti : Attraverso lacomunicazioneal sistemadellaregionedi spaziochedeveessereridisegnataperchèmodificata, si provvedead un rinfresco più rapido dellavisualizzazioneper unamaggiorevelocitàcomplessiva.
112
Seleziona
l’oggetto inserendolo nella lista degli oggetti selezionati m_sel ect i on che è
unavariabilemembro dellaclasse ‘Vista’
K vir tual CPoint GetHandle(int count, CDrawObj **pArc)
Restituisce la posizione del link numero L count M insieme (se esiste) all’arco ad
esso agganciato
K vir tual CDrawObj* EvaluateUpperLink(CSFCView* pView, int* i, int j )
Controlla se il/i link superiore/i di un’oggetto sono compatibili con un aggancio
diretto con un altro oggetto ene restituisce il puntatore
K vir tual CDrawObj* EvaluateLowerL ink(CSFCView* pView, int* i, int j )
Controlla se il/i link inferiore/i di un’oggetto sono compatibili con un aggancio
diretto con un altro oggetto ene restituisce il puntatore
K vir tual void Remove()
Cancella dallamemoria l’oggetto
K vir tual int maxCount()
Restituisceil numero (del nome) più alto tragli oggetti dell’SFC per assegnareun
nome progressivo al nuovo oggetto
K vir tual void Ser ialize (CArchive& )
Funzionedi salvataggio su disco delle informazioni associateall’oggetto4
NN.B. I puntatori agli oggetti collegati non possono essere salvati e poi ricostruiti perchè indirizzi dinamici; per questoviene eseguita, all’atto della registrazione, una assolutizzazione degli indirizzi degli oggetti per consentire di ricostruirnesuccessivamente i legami. Taleoperazione verrà illustrata in seguito.
113
O vir tual BOOL Check(int & war, int & er r)
Controllo sintattico del singolo oggetto
O vir tual CStr ing TextualForm()
Restituisce una stringa che rappresenta la traduzione in Meta Linguaggio
dell’oggetto, dei suoi collegamenti edei suoi record
O vir tual void OnEditProperty(CSFCView *pView)
Richiama la finestradi proprietàspecificadell’oggetto.
4.2.2 CSFCDoc
Questa classe, insieme alla classe della ‘vista’ CSFCView, gestisce alcune tra le più
importanti funzonalità dell’ intero programma. Essa in particolare si occupa delle
operazioni di I/O per ogni formato di file gestible dal progamma (sono 3 in tutto
: progetto * .prj, sfc singolo * .sfc e Meta File * .mlf). In quest’ambito sono state
implementate le funzioni di gestione delle strutturedi dati che contengono l’ immagine
degli SFC. Qui troviamo inoltrealcunedellefunzioni attivatedirettamentedai messaggi
di Windows checorrispondono agli eventi elaborati dell’applicazione.
Memor izzazionesu filedell’SFC
Il Visual C++ e in particolare le MFC di Windows mettono a disposizione
del programmatore una infrastruttura di funzioni che gestiscono agevolmente la
serializzazione, ossia la scrittura su dispositivo di memorizzazione permanente, dei
recordsassociati ad ognuno degli oggetti checompongono il documento.
114
E’ stata allora implementata una funzione virtuale ‘‘Serialize’’ specifica per ogni
Q BOOL CheckSFC(void);Q CStr ing ErrorStr (int err );Q CStr ing WarningStr(int war);
116
4.2.3 CSFCView
La classe è derivata da CScr ol l Vi ew di MFC che gestisce, oltre alle funzioni
necessarie per il disegno, anche quelle di scrolling orizzontale e verticale della vista
dell’areadi lavoro. Di solito in questaclasseconf luiscono tutte le funzioni (richiamate
o meno da eventi Windows) che gestiscono ciò che dovrà essere visualizzato e
gli strumenti per disegnare, come le funzioni di conversione da coordinate logiche
a coordinate di dispositivo, di zoom, di refresh video, di stampa, di selezione e
spostamento degli oggetti ecc...
A proposito delle funzioni cherispondono agli eventi, in particolaredel mouse, esse
vengono dirottatesul codicechedescriveil comportamento del programmain relazione
al particolare tool selezionato. Così gli eventi di click, doppio click, movimento mouse
ecc... sono dirottati sulle funzioni omologhe implementate nelle classi CPhaseTool ,
CTr ansTool , CMul t i Tool , CAr cTool e CSel ect Tool .
Descriviamo sommariamente le funzioni più importanti, tralasciando quelle che si
occupano dellagestionedellavisualizzazione dei pulsanti o dei menù.
R vir tual void OnDraw(CDC* pDC)
La funzione più importante è OnDraw, una funzione virtuale predefinita che è
necessario editareper comunicare leoperazioni di disegno. Al suo interno èstato
implementato un breve ma efficace algoritmo per velocizzare le operazioni di
disegno :CDC dc;CDC* pDr awDC = pDC;CBi t map bi t map;CBi t map* pOl dBi t map;
/ / onl y pai nt t he r ect t hat needs r epai nt i ngCRect cl i ent ;pDC- >Get Cl i pBox( cl i ent ) ;CRect r ect = cl i ent ;DocToCl i ent ( r ect ) ;
117
/ / dr aw t o of f scr een bi t map f or f ast l ooki ng r epai nt si f ( dc. Cr eat eCompat i bl eDC( pDC) ){
i f ( bi t map. Cr eat eCompat i bl eBi t map( pDC, r ect . Wi dt h( ) , r ect . Hei ght ( ) ) ){
OnPr epar eDC( &dc, NULL) ;pDr awDC = &dc;
/ / of f set or i gi n mor e because bi t map i s j ust pi ece of t he whol e dr awi ngdc. Of f set Vi ewpor t Or g( - r ect . l ef t , - r ect . t op) ;pOl dBi t map = dc. Sel ect Obj ect ( &bi t map) ;dc. Set Br ushOr g( r ect . l ef t % 8, r ect . t op % 8) ;
/ / mi ght as wel l c l i p t o t he same r ect angl edc. I nt er sect Cl i pRect ( cl i ent ) ;
}}
}
. . . di segna i l cont enut o del l ’ ar ea di l avor o . . .
i f ( pDr awDC ! = pDC){
pDC- >Set Vi ewpor t Or g( 0, 0) ;pDC- >Set Wi ndowOr g( 0, 0) ;pDC- >Set MapMode( MM_TEXT) ;dc. Set Vi ewpor t Or g( 0, 0) ;dc. Set Wi ndowOr g( 0, 0) ;dc. Set MapMode( MM_TEXT) ;pDC- >Bi t Bl t ( r ect . l ef t , r ect . t op, r ect . Wi dt h( ) , r ect . Hei ght ( ) ,
&dc, 0, 0, SRCCOPY) ;dc. Sel ect Obj ect ( pOl dBi t map) ;
}
In pratica tale insieme di istruzioni consente di disegnare in un nuovo e diverso
contesto di dispositivo (DeviceContext ) creato manon visualizzato, ecopiato sul
DC associato allavisualizzazionesolo quando tutte leoperazioni di disegno sono
terminate.
S vir tual void OnPrepareDC(CDC* pDC, CPr intInfo* pInfo = NULL)
In qusta funzione viene preparato il contesto di dispositivo sul quale dovranno
essere riversati i comandi di disegno e si occupa quindi anche del contesto
‘stampante’ dividendo, se necessario, il documento su più fogli di carta come
st r uct node {i nt number ;BOOL pl aced;BOOL count ed;CPoi nt posi t i on;i nt wi dt h;CLi st <st r uct node * , st r uct node * > down;CLi st <st r uct node * , st r uct node * > up;
} ;
CMap <i nt , i nt , st r uct node * , st r uct node * > St epLi st ;CMap <i nt , i nt , st r uct node * , st r uct node * > Tr ansLi st ;
120
L’algor itmo di Import del singolo SFCsi componeessenzialmentedei segunti passi
:
1) Immissionedegli elementi passoetransizionedirettamentenel documentoattraverso
una prima scansionedel file
2) Costruzionedelledue listea partiredai dati degli oggetti del documento
3) Aggiornamento dei link all’ interno dei nodi delle liste attraverso un’ulteriore
scansionedel file
4) Posizionamento degli elementi
5) Aggiornamento delleposizioni degli elementi del documento
6) Aggiornamento dei link tra gli oggetti del documento
Occupiamoci in dettaglio dei vari passi.
1) Vieneeseguitalaprimascansioneeinterpretazionesintatticadel testoal f ineunicodi
inseriretutti gli oggetti passoetransizioneall’ internodellalistapObj Li st corrente.
In questafasei collegamenti tragli oggetti non sono ancorastati definiti, nèvengono
presi in considerazionenella sintassi del testo.
2) Viene creata un’ immagine degli elementi del documento appena inseriti andando a
compilare la listadei Passi edelleTransizioni
3) Viene eseguita una seconda scansione del testo in Meta Linguaggio per individuare
i collegamenti tra gli oggetti econtemporaneamentevengono aggiornati i link tra le
due liste.
4) Viene eseguito l’algoritmo di posizionamento (la versione completa del listato
è in appendice). Possiamo provare ad evidenziarne i passaggi, descrivendoli in
linguaggio naturale :
a) Esso iniziacol cercarelafaseiniziale, chedevenecessariamenteesserenumerata
con 1, e che, come già detto, non deve far parte di uno dei rami paralleli di un
oggetto MultiLink. Ad essa viene assegnata una posizione iniziale e diventa il
nodo corrente. In tal modo si instaura una sorta di gerarchia tra i nodi del
grafo, facendolo assomigliarepiù ad un albero ma con la possibilità cheun figlio
abbia più di un padre; la fase iniziale rappresenta il nodo di livello 1.Notiamo
esplicitamentecheai fini del posizionamento non impor ta se il nodo corrente
121
sia un passo o una transizione. Per ogni nodo correntesi ha :
b) Controlla i link figli (verso il basso) : se c’è un unico figlio, posiziona
direttamente l’oggetto, lo marca e lo fa diventare il nodo corrente, altrimenti
assegna una posizione a tutti gli oggetti f igli che vengono marcati e inseristi in
uno stack.
c) Senon esiste il nodo correnteprendedallo stack il successivo elemento, lo rende
nodo correntee tornaal punto b) finchè lo stack non si svuota.
d) A questo punto tutti i rami ‘ in apertura’ del grafo che era possibile inserire
sono stati posizionati; bisogna ora posizionare gli oggetti che chiudono le
divergenze introdotte. Essi vengono cercati tra gli oggetti non ancora marcati
come ‘posizionati’ evengono inseriti se i loro padri sono tutti stati posizionati.
e) Se viene trovato quindi un oggetto che chiude una divergenza, esso viene
posizionato, marcato e diventa il nuovo nodo corrente e l’algoritmo riprende
dal punto a), altrimenti, se non ci sono più oggetti da posizionare l’algoritmo
ha termine.
f) A questo punto le due liste contengono gli oggetti con le loro posizioni.
Osserviamo che lo stesso algoritmo di posizionamento viene ripetuto due volte
malaprimavoltasolo per effettuare lo stesso tipo di visitaal finedi determinare
lalarghezzadelledivergenzeper evitareil più possibilelasovrapposizionetragli
oggetti derivanti dabiforcazioni diverseeinnestate. Infatti il tipost r uct node
contiene la variabilemembro wi dt h checontiene la spaziaturaorizzontale tra i
suoi oggetti f igli.
5) Viene ora calcolata la massima estensione di tutto il grafo e applicato un offset alle
posizioni qualora queste escano fuori dai confini sinistro e alto del documento. In
seguito leposizioni calcolatevengono trasferite agli oggetti del documento.
6) In base alle informazioni sui link del grafo e alle posizioni vengono ceati gli
archi orientati tra gli oggetti del documento ed inseriti, dove necessario, gli oggetti
MultiLink.
Le funzioni più importanti che sono state d’ausilio all’ implementazione
dell’algoritmo sono:
122
V BOOL ComputeFromBottom(struct node* pNode);V BOOL Inser tFromBottom(struct node*pNode);
Hanno lastessainfrastrutturaeservonoavedereseil nodochevieneloropassatoè
possibileinserirlo achiusuradi unadivergenza, nel qual caso restituiscono TRUE
e marcano il nodo. La prima serve nell’operazione di calcolo delle larghezze tra
gli oggetti di rami paralleli, mentre la seconda nell’algoritmo di posizionamento
vero e proprio (viene, in quest’ultima funzione, assegnata anche la posizione al
nodo).
V void SortByX(struct node* pNode);
Questa funzione ordina la lista dei padri e dei figli del nodo passatogli secondo
la loro posizioneorizzontale; servequando bisognacollegareelementi ad oggetti
MultiLink sul ramo parallelo per evitarechegli archi si incrocino tra loro.
123
5 Esempi di output
5.1 Esempio 1
figura 23: Output di esempio del programma (1)
FILE MLF RELATIVO ALL’SFC DI FIG.23
BEGI N_PROJECT;
SFC 1 : NoName;I NI TI AL_STEP S101 : No Act i on( N) : END_STEP; / * di chi ar azi one di PASSO * /TRANSI TI ON T101 FROM S101 TO ( S103, S102) : = TRUE; / * PARALLELI SMO * /TRANSI TI ON T102 FROM S101 TO S104 : = TRUE; / * di chi ar azi one di t r ansi zi one * /STEP S102 : No Act i on( N) : END_STEP;STEP S103 : No Act i on( N) : END_STEP;STEP S104 : No Act i on( N) : END_STEP;TRANSI TI ON T103 FROM S102 TO S105 : = TRUE; / / quest a e l a successi va det er mi nanoTRANSI TI ON T104 FROM S104 TO S105 : = TRUE; / * una CONVERGENZA * /STEP S105 : No Act i on( N) : END_STEP;TRANSI TI ON T105 FROM ( S103, S105) TO S106 : = TRUE; / * SI NCRONI ZZAZI ONE * /STEP S106 : No Act i on( N) : END_STEP;END_SFC;
124
END_PROJECT;
5.2 Esempio 2
In quest’altro esempio si osserva l’uso dei qualif icatori d’azione, e come essi vengono
tradotti in MetaLinguaggio.
figura 24: Output di esempio del programma (2)
FILE MLF RELATIVO ALL’SFC DI FIG.23BEGI N_PROJECT;
SFC 1 : NoName;I NI TI AL_STEP S101 : Fi l l ( D, T#0d_0h_5m_30s_50ms) : END_STEP;TRANSI TI ON T101 FROM S101 TO ( S102, S103) : = l evel > 10. 5;STEP S102 : Mi x( L, T#0d_0h_5m_30s_50ms) : END_STEP;STEP S103 : war m up( N) : END_STEP;TRANSI TI ON T102 FROM ( S102, S103) TO S101 : = T > 100;END_SFC;
END_PROJECT;
125
AppendiceA
CodiceSorgentedel Programma SFCEditor
Nellepaginecheseguono vieneriportato il codicesorgentedel programmaSFC Editor.
Per ogni classe, Microsoft Visual C++ riserva due file, uno per le dichiarazioni (.h) e
uno per il codice applicativo (.cpp)
126
classCActionDlg
ActionDlg.h’ ’ ’ ’ #i f ! def i ned( AFX_ACTI ONDLG_H__547AF100_0542_11D3_8FB1_D93140D57746__I NCLUDED_)#def i ne AFX_ACTI ONDLG_H__547AF100_0542_11D3_8FB1_D93140D57746__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / Act i onDl g. h : header f i l e/ /
cl ass CAct i onDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CTi mer m_t i me;CAct i onDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CAct i onDl g)enum { I DD = I DD_ACTI ON_DI ALOG } ;CSt r i ng m_name;i nt m_number ;CSt r i ng m_qual i f i er ;BOOL m_i ni t i al ;CSt r i ng m_t i meSt r ;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CAct i onDl g)
pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CAct i onDl g)af x_msg voi d OnSpecTi me( ) ;/ / } } AFX_MSG
DECLARE_MESSAGE_MAP( )} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_ACTI ONDLG_H__547AF100_0542_11D3_8FB1_D93140D57746__I NCLUDED_)
ActionDlg.cpp
127
/ / Act i onDl g. cpp : i mpl ement at i on f i l e/ /
#i ncl ude ’ ’ st daf x. h’ ’#i ncl ude ’ ’ SFC. h’ ’#i ncl ude ’ ’ Act i onDl g. h’ ’#i ncl ude ’ ’ Ti meDl g. h’ ’#i ncl ude ’ ’ PhaseObj . h’ ’
#i f def _DEBUG#def i ne new DEBUG_NEW#undef THI S_FI LEst at i c char THI S_FI LE[ ] = __FI LE__;#endi f
CAct i onDl g: : CAct i onDl g( CWnd* pPar ent / * =NULL* / ): CDi al og( CAct i onDl g: : I DD, pPar ent )
{/ / { { AFX_DATA_I NI T( CAct i onDl g)m_name = _T( ’ ’ ’ ’ ) ;m_number = 0;m_qual i f i er = _T( ’ ’ ’ ’ ) ;m_i ni t i al = FALSE;m_t i meSt r = _T( ’ ’ ’ ’ ) ;/ / } } AFX_DATA_I NI T
}
voi d CAct i onDl g: : DoDat aExchange( CDat aExchange* pDX){
CDi al og: : DoDat aExchange( pDX) ;/ / { { AFX_DATA_MAP( CAct i onDl g)DDX_Text ( pDX, I DC_EDI T_ACTI ON_NAME, m_name) ;DDV_MaxChar s( pDX, m_name, 30) ;DDX_Text ( pDX, I DC_EDI T_STEP_NUM, m_number ) ;DDV_Mi nMaxI nt ( pDX, m_number , 0, 99) ;DDX_CBSt r i ng( pDX, I DC_ACTI ON_QUALF, m_qual i f i er ) ;DDX_Check( pDX, I DC_I NI TI AL, m_i ni t i al ) ;DDX_Text ( pDX, I DC_TI ME_STRI NG, m_t i meSt r ) ;/ / } } AFX_DATA_MAP
}
BEGI N_MESSAGE_MAP( CAct i onDl g, CDi al og)/ / { { AFX_MSG_MAP( CAct i onDl g)ON_BN_CLI CKED( I DC_SPEC_TI ME, OnSpecTi me)/ / } } AFX_MSG_MAP
/ / TODO: Add your cont r ol not i f i cat i on handl er code her eUpdat eDat a( TRUE) ;
CTi meDl g t _dl g( t hi s) ;
t _dl g. m_days = m_t i me. d;t _dl g. m_hour s = m_t i me. h;
128
t _dl g. m_mi n = m_t i me. m;t _dl g. m_sec = m_t i me. s;t _dl g. m_msec = m_t i me. ms;
i f ( t _dl g. DoModal ( ) == I DOK){
/ / r et r i eve t he di al og dat am_t i me. d = t _dl g. m_days;m_t i me. h = t _dl g. m_hour s;m_t i me. m = t _dl g. m_mi n;m_t i me. s = t _dl g. m_sec;m_t i me. ms = t _dl g. m_msec;m_t i meSt r = m_t i me. Ti meSt r i ng( ) ;Updat eDat a( FALSE) ;
}}
classCArcObj
File : ArcObj .h/ / Ar cObj . h: i nt er f ace f or t he CAr cObj cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_ARCOBJ_H__AE826184_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_)#def i ne AFX_ARCOBJ_H__AE826184_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Dr awObj . h’ ’
c l ass CAr cObj : publ i c CDr awObj{
DECLARE_SERI AL ( CAr cObj )
publ i c:/ / member f unct i onCAr cObj ( ) ;vi r t ual ~CAr cObj ( ) ;vi r t ual voi d Ser i al i ze( CAr chi ve& ar ) ;vi r t ual voi d Remove( ) ;vi r t ual voi d Sel ect I t em( CSFCVi ew * pVi ew) ;vi r t ual i nt Hi t Test ( CPoi nt poi nt ) ;voi d AddPoi nt ( const CPoi nt & poi nt ) ;vi r t ual voi d Dr awI t em( CSFCVi ew* pVi ew, CDC * pDC) ;voi d MovePt To( CSFCVi ew* pVi ew, CPoi nt del t a) ;
/ / member var i abl esi nt m_nPoi nt s;i nt m_nAl l ocPoi nt s;CPoi nt * m_poi nt s;
} ;
#endi f / / ! def i ned( AFX_ARCOBJ_H__AE826184_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_)
129
File : ArcObj .cpp
/ / Ar cObj . cpp: i mpl ement at i on of t he CAr cObj cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
doubl e di st ;CPoi nt of f set ;CPoi nt pt 1, pt 2;
/ / dr aw poi nt s sel ect edf or ( i nt i = 0; i < m_nPoi nt s; i ++){
pt 1 = CPoi nt ( m_poi nt s[ i ] . x* m_gr i d, m_poi nt s[ i ] . y* m_gr i d) ;i f ( pVi ew- >m_pt Sel ect i on. Fi nd( &m_poi nt s[ i ] ) )
Dr awCi r cl e( pt 1, m_di m/ 12, pDC) ;}
pt 1 = CPoi nt ( m_poi nt s[ 0] . x* m_gr i d, m_poi nt s[ 0] . y* m_gr i d) ;pDC- >MoveTo( pt 1) ;
f or ( i = 1; i < m_nPoi nt s; i ++){
pt 1 = CPoi nt ( m_poi nt s[ i ] . x* m_gr i d, m_poi nt s[ i ] . y* m_gr i d) ;pt 2 = CPoi nt ( m_poi nt s[ i - 1] . x* m_gr i d, m_poi nt s[ i - 1] . y* m_gr i d) ;
of f set = pt 1 - pt 2;di st = sqr t ( of f set . x* of f set . x + of f set . y* of f set . y) ;
pDC- >Li neTo( pt 1) ;
/ / dr aw ar r owi f ( di st > m_di m/ 2){
i nt k = m_di m/ 9;CPoi nt c , p1, p2, p3;doubl e _si n = of f set . y/ di st ;doubl e _cos = of f set . x/ di st ;
of f set . x = of f set . x/ 2;of f set . y = of f set . y/ 2;
c = pt 2 + of f set ;
p1. x = ( l ong) ( c. x - k * _si n) ;p1. y = ( l ong) ( c. y + k * _cos) ;
p2. x = ( l ong) ( c. x + k * _si n) ;p2. y = ( l ong) ( c. y - k * _cos) ;
p3. x = ( l ong) ( c. x + 2. 5* k * _cos) ;p3. y = ( l ong) ( c. y + 2. 5* k * _si n) ;
}i f ( ( pos ! = NULL) && ( ! pDC- >I sPr i nt i ng( ) ) )
pDC- >Sel ect Obj ect ( pOr i gi nal Pen) ;}
voi d CAr cObj : : MovePt To( CSFCVi ew* pVi ew, CPoi nt del t a){
pVi ew- >I nval Ar c( t hi s, m_nPoi nt s- 1) ;
f or ( i nt i =0; i <m_nPoi nt s; i ++)i f ( pVi ew- >m_pt Sel ect i on. Fi nd( &( m_poi nt s[ i ] ) ) )
m_poi nt s[ i ] += del t a;
pVi ew- >I nval Ar c( t hi s, m_nPoi nt s- 1) ;}
i nt CAr cObj : : Hi t Test ( CPoi nt poi nt ){
i f ( m_nPoi nt s > 1){
doubl e di st ;CPoi nt p1, p2;CPoi nt p3 = CPoi nt ( poi nt . x* m_gr i d, poi nt . y* m_gr i d) ;CRect r ect ;
f or ( i nt i = 0; i < m_nPoi nt s- 1; i ++){
p1 = CPoi nt ( m_poi nt s[ i ] . x* m_gr i d, m_poi nt s[ i ] . y* m_gr i d) ;p2 = CPoi nt ( m_poi nt s[ i +1] . x* m_gr i d, m_poi nt s[ i +1] . y* m_gr i d) ;r ect . Set Rect ( p1. x, p1. y, p2. x, p2. y) ;r ect . Nor mal i zeRect ( ) ;r ect . I nf l at eRect ( m_gr i d, m_gr i d) ;
i f ( r ect . Pt I nRect ( p3) ){
di st = abs( ( p1. x- p3. x) * ( p2. y- p3. y) - ( p2. x- p3. x) * ( p1. y- p3. y) ) ;di st = di st / sqr t ( ( p1. x- p2. x) * ( p1. x- p2. x) +( p1. y- p2. y) * ( p1. y- p2. y) ) ;i f ( di st <= m_gr i d/ 2)
r et ur n 100; / / code f or ar r ow}
}}
r et ur n 0;}
voi d CAr cObj : : Sel ect I t em( CSFCVi ew * pVi ew){
i f ( ! pVi ew- >m_sel ect i on. Fi nd( t hi s) )pVi ew- >m_sel ect i on. AddTai l ( t hi s) ;
}
voi d CAr cObj : : Remove( ){
132
CDr awObj * pObj ;i nt i ;pObj = m_Lower [ 0] ;i f ( pObj ! = NULL){
f or ( i =0; i < ( pObj - >m_nLower Li nk) ; i ++)i f ( pObj - >m_Lower [ i ] == t hi s)
pObj - >m_Lower [ i ] = NULL;
f or ( i =0; i < ( pObj - >m_nUpper Li nk) ; i ++)i f ( pObj - >m_Upper [ i ] == t hi s)
pObj - >m_Upper [ i ] = NULL;
}pObj = m_Upper [ 0] ;i f ( pObj ! = NULL){
f or ( i =0; i < ( pObj - >m_nLower Li nk) ; i ++)i f ( pObj - >m_Lower [ i ] == t hi s)
pObj - >m_Lower [ i ] = NULL;
f or ( i =0; i < ( pObj - >m_nUpper Li nk) ; i ++)i f ( pObj - >m_Upper [ i ] == t hi s)
pObj - >m_Upper [ i ] = NULL;
}
del et e t hi s;}
voi d CAr cObj : : Ser i al i ze( CAr chi ve & ar ){
CDr awObj : : Ser i al i ze( ar ) ;
i nt i ;i f ( ar . I sSt or i ng( ) ){
ar << m_nAl l ocPoi nt s;ar << m_nPoi nt s;f or ( i =0; i <m_nAl l ocPoi nt s; i ++)
ar << m_poi nt s[ i ] ;}el se{
ar >> m_nAl l ocPoi nt s;ar >> m_nPoi nt s;CPoi nt * newPoi nt s = new CPoi nt [ m_nAl l ocPoi nt s] ;m_poi nt s = newPoi nt s;
f or ( i =0; i <m_nAl l ocPoi nt s; i ++)ar >> m_poi nt s[ i ] ;
}
}
classCArcTool
File : ArcTool.h
133
/ / Ar cTool . h: i nt er f ace f or t he CAr cTool cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_ARCTOOL_H__C6C2E0C1_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_)#def i ne AFX_ARCTOOL_H__C6C2E0C1_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CAr cTool{publ i c:
/ / member f unct i onst at i c voi d OnLBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;st at i c voi d OnMouseMove( CSFCVi ew* pVi ew, UI NT nFl ags, const CPoi nt & poi nt ) ;st at i c voi d OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;st at i c CAr cObj * OnNewAr c( CDr awObj * f i r st , CDr awObj * l ast , i nt n_f i r st , i nt n_l ast ) ;CAr cTool ( ) ;vi r t ual ~CAr cTool ( ) ;
/ / member var i abl esst at i c CPoi nt c_down;st at i c CPoi nt c_l ast ;st at i c BOOL dr awi ng;
} ;
#endi f / / ! def i ned( AFX_ARCTOOL_H__C6C2E0C1_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_)
CPoi nt CAr cTool : : c_down;CPoi nt CAr cTool : : c_l ast ;
BOOL CAr cTool : : dr awi ng = FALSE;
CAr cTool : : CAr cTool ( ){}
134
CAr cTool : : ~CAr cTool ( ){
}
voi d CAr cTool : : OnLBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
CPoi nt l ocal = poi nt ;pVi ew- >Cl i ent ToDoc( l ocal ) ;l ocal = pVi ew- >Near est OnGr i d( l ocal ) ;
CDr awObj * pObj ;CAr cObj * pAr c;
BOOL sel = FALSE;c_down = l ocal ;c_l ast = l ocal ;
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * t est ;
whi l e ( pos ! = NULL && ! sel ){
pObj = pObj Li st - >Get Next ( pos) ;i nt hi t = pObj - >Hi t Test ( l ocal ) ;pObj - >Get Handl e( hi t , &t est ) ;i f ( ( hi t > 1) && ( hi t < 100) && ( t est == NULL) ){
sel = TRUE;
i f ( ! dr awi ng) / / new ar c !{
/ / MessageBeep( 0) ;/ / i nser t f i r st poi nt and f l oat i ng second poi ntpAr c = new ( CAr cObj ) ;pAr c- >AddPoi nt ( l ocal ) ;pAr c- >AddPoi nt ( l ocal ) ;
pObj Li st - >AddTai l ( pAr c) ;
pAr c- >m_Upper [ 0] = pObj ;
i f ( ( hi t >= 20) && ( hi t < 30) )pObj - >m_Upper [ hi t - 20] = pAr c;
el se i f ( ( hi t >= 30) && ( hi t < 40) )pObj - >m_Lower [ hi t - 30] = pAr c;
dr awi ng = TRUE;pVi ew- >I nval Ar c( pAr c, - 1) ;
}el se / / end of ar c !{
/ / l ast i nser t ed obj i s an ar cpAr c = ( CAr cObj * ) pObj Li st - >Get Tai l ( ) ;
pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] = l ocal ;pAr c- >m_Lower [ 0] = pObj ;
i f ( ( hi t >= 20) && ( hi t < 30) )pObj - >m_Upper [ hi t - 20] = pAr c;
el se i f ( ( hi t >= 30) && ( hi t < 40) )pObj - >m_Lower [ hi t - 30] = pAr c;
135
dr awi ng = FALSE;pVi ew- >I nval Ar c( pAr c, - 1) ;
}}
}
i f ( ! sel && dr awi ng){
/ / i nser t new poi nt/ / ( l ast i nser t ed obj i s an ar c)pAr c = ( CAr cObj * ) pObj Li st - >Get Tai l ( ) ;pAr c- >AddPoi nt ( l ocal ) ;
}}
voi d CAr cTool : : OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags, const CPoi nt & poi nt ){
i f ( dr awi ng){
CCl i ent DC dc( pVi ew) ;
CAr cObj * cur r ent = ( CAr cObj * ) pObj Li st - >Get Tai l ( ) ;CPoi nt saveLast ;
i f ( cur r ent ! = NULL){
CPoi nt l ocal = poi nt ;pVi ew- >Cl i ent ToDoc( l ocal ) ;CRect r ect ;
CPoi nt del t a = c_l ast - l ocal ;i f ( pVi ew- >Near est OnGr i d( l ocal ) ! = cur r ent - >m_poi nt s[ cur r ent - >m_nPoi nt s - 1] )
{pVi ew- >I nval Ar c( cur r ent , 1) ;
cur r ent - >m_poi nt s[ cur r ent - >m_nPoi nt s - 1] = pVi ew- >Near est OnGr i d( l ocal ) ;c_l ast = l ocal ;
pVi ew- >I nval Ar c( cur r ent , 1) ;
pVi ew- >Updat eWi ndow( ) ;}
}}
}
CAr cObj * CAr cTool : : OnNewAr c( CDr awObj * f i r st , CDr awObj * l ast ,i nt n_f i r st , i nt n_l ast )
{CDr awObj * t emp;CAr cObj * pAr c = new ( CAr cObj ) ;/ / i nser t f i r st poi nt and f l oat i ng second poi nt
pObj Li st - >AddTai l ( pAr c) ;
pAr c- >AddPoi nt ( f i r st - >Get Handl e( n_f i r st +30, &t emp) ) ;pAr c- >AddPoi nt ( l ast - >Get Handl e( n_l ast +20, &t emp) ) ;
pAr c- >m_Upper [ 0] = f i r st ;pAr c- >m_Lower [ 0] = l ast ;f i r st - >m_Lower [ n_f i r st ] = pAr c;l ast - >m_Upper [ n_l ast ] = pAr c;
r et ur n pAr c;
136
}
voi d CAr cTool : : OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
i f ( dr awi ng){
i f ( ! pObj Li st - >I sEmpt y( ) ){
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}pVi ew- >I nval i dat e( ) ;dr awi ng = FALSE;
}el se
m_Obj Tool = sel ect i on;}
classCCheckDlg
File : CheckDlg.h#i f ! def i ned( AFX_CHECKDLG_H__6B1C1F82_700C_11D3_8FB1_930A064B0E50__I NCLUDED_)#def i ne AFX_CHECKDLG_H__6B1C1F82_700C_11D3_8FB1_930A064B0E50__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / CheckDl g. h : header f i l e/ /
#def i ne WM_GOODBYE WM_USER + 5#def i ne WM_CHECK_AGAI N WM_USER + 4
cl ass CCheckDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CCheckDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct orCCheckDl g( CVi ew* pVi ew) ;BOOL Cr eat e( ) ;
/ / Di al og Dat a/ / { { AFX_DATA( CCheckDl g)enum { I DD = I DD_OUTPUT_DLG } ;CPr ogr essCt r l m_pr og;CSt r i ng m_r esul t s;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CCheckDl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t
137
/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CCheckDl g)vi r t ual voi d OnOK( ) ;vi r t ual BOOL OnI ni t Di al og( ) ;af x_msg voi d OnAgai nBut t on( ) ;/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
pr i vat e:CVi ew* m_pVi ew;
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_CHECKDLG_H__6B1C1F82_700C_11D3_8FB1_930A064B0E50__I NCLUDED_)
File : CheckDlg.cpp/ / CheckDl g. cpp : i mpl ement at i on f i l e/ /
/ / TODO: Add ext r a i ni t i al i zat i on her em_pr og. Set Range( 0, 100) ;m_pr og. Set Pos( 0) ;
r et ur n TRUE; / / r et ur n TRUE unl ess you set t he f ocus t o a cont r ol/ / EXCEPTI ON: OCX Pr oper t y Pages shoul d r et ur n FALSE
}
voi d CCheckDl g: : OnAgai nBut t on( ){
/ / TODO: Add your cont r ol not i f i cat i on handl er code her eUpdat eDat a( TRUE) ;m_pVi ew- >Post Message( WM_CHECK_AGAI N, NULL) ;
}
classCDocPageDlg
File : DocPageDlg.h#i f ! def i ned( AFX_DOCPAGEDLG_H__AD66BB80_66D3_11D3_8FB1_D03EA30B2729__I NCLUDED_)#def i ne AFX_DOCPAGEDLG_H__AD66BB80_66D3_11D3_8FB1_D03EA30B2729__I NCLUDED_
139
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / DocPageDl g. h : header f i l e/ /
cl ass CDocPageDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CDocPageDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CDocPageDl g)enum { I DD = I DD_PAGESI ZE_DI ALOG } ;i nt m_hei ght ;i nt m_wi dt h;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CDocPageDl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CDocPageDl g)af x_msg voi d OnAut oSi ze( ) ;/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_DOCPAGEDLG_H__AD66BB80_66D3_11D3_8FB1_D03EA30B2729__I NCLUDED_)
File : DocPageDlg.cpp/ / DocPageDl g. cpp : i mpl ement at i on f i l e/ /
/ / TODO: Add your cont r ol not i f i cat i on handl er code her ei nt dx = - 10000, bt = - 10000;POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
CDr awObj * pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_posi t i on. x > dx)
dx = pObj - >m_posi t i on. x;i f ( pObj - >m_posi t i on. y > bt )
bt = pObj - >m_posi t i on. y;}m_wi dt h = ( dx+5) * m_gr i d/ 10;m_hei ght = ( bt +5) * m_gr i d/ 10;
Updat eDat a( FALSE) ;}
classCDrawArc
File : DrawArc.h/ / Dr awAr c. h: i nt er f ace f or t he CDr awAr c cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
141
#i f ! def i ned( AFX_DRAWARC_H__EF028A22_EE6E_11D2_8FB1_C0C9BCA7FE02__I NCLUDED_)#def i ne AFX_DRAWARC_H__EF028A22_EE6E_11D2_8FB1_C0C9BCA7FE02__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CSFCDoc;cl ass CSFCVi ew;
cl ass CDr awAr c : publ i c CObj ect{publ i c:
CDr awAr c( ) ;vi r t ual ~CDr awAr c( ) ;
CDr awObj * pFi r st ;CDr awObj * pLast ;
vi r t ual voi d Dr awI t em( CSFCVi ew* pVi ew, CDC * pDC) ;vi r t ual voi d AddPoi nt ( const CPoi nt & poi nt ) ;voi d MoveTo( CSFCVi ew* pVi ew, CPoi nt del t a) ;
/ / pr ot ect ed:CDr awAr c * m_pAr cObj ;
i nt m_nPoi nt s;i nt m_nAl l ocPoi nt s;CPoi nt * m_poi nt s;
f r i end cl ass CAr cTool ;} ;
#endi f / / ! def i ned( AFX_DRAWARC_H__EF028A22_EE6E_11D2_8FB1_C0C9BCA7FE02__I NCLUDED_)
File : Drawarc.cpp/ / Dr awAr c. cpp: i mpl ement at i on of t he CDr awAr c cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
m_poi nt s = NULL;m_nPoi nt s = 0;m_nAl l ocPoi nt s = 0;
pFi r st = NULL;pLast = NULL;
}
CDr awAr c: : ~CDr awAr c( ){
i f ( m_poi nt s ! = NULL)del et e[ ] m_poi nt s;
}
voi d CDr awAr c: : AddPoi nt ( const CPoi nt & poi nt ){
ASSERT_VALI D( t hi s) ;/ / Al l oco di eci punt i per vol t a per r i spar mi ar ei f ( m_nPoi nt s == m_nAl l ocPoi nt s){
CPoi nt * newPoi nt s = new CPoi nt [ m_nAl l ocPoi nt s + 10] ;i f ( m_poi nt s ! = NULL){
memcpy( newPoi nt s, m_poi nt s, si zeof ( CPoi nt ) * m_nAl l ocPoi nt s) ;del et e[ ] m_poi nt s;
}m_poi nt s = newPoi nt s;m_nAl l ocPoi nt s += 10;
}}
voi d CDr awAr c: : Dr awI t em( CSFCVi ew* pVi ew, CDC * pDC){
CPen MyPen;CPen * pOr i gi nal Pen;MyPen. Cr eat ePen( PS_SOLI D, 1, RGB( 0, 0, 0) ) ;pOr i gi nal Pen = pDC- >Sel ect Obj ect ( &MyPen) ;CRect r ect ;
i f ( m_nPoi nt s > 1){
doubl e di st ;CPoi nt of f set ;
pDC- >MoveTo( m_poi nt s[ 0] ) ;
i f ( pVi ew- >m_pt Sel ect i on. Fi nd( &m_poi nt s[ 0] ) ){
r ect . Set Rect ( m_poi nt s[ 0] . x, m_poi nt s[ 0] . y, m_poi nt s[ 0] . x, m_poi nt s[ 0] . y) ;r ect . I nf l at eRect ( 3, 3) ;pDC- >El l i pse( r ect ) ;
}
f or ( i nt i = 1; i < m_nPoi nt s; i ++){
of f set = m_poi nt s[ i ] - m_poi nt s[ i - 1] ;di st = sqr t ( of f set . x* of f set . x + of f set . y* of f set . y) ;
pDC- >Li neTo( m_poi nt s[ i ] ) ;
/ / di segna l a f r ecci a
143
i f ( di st > m_di m/ 2){
i nt k = m_di m/ 9;CPoi nt c , p1, p2, p3;doubl e _si n = of f set . y/ di st ;doubl e _cos = of f set . x/ di st ;
of f set . x = of f set . x/ 2;of f set . y = of f set . y/ 2;
c = m_poi nt s[ i - 1] + of f set ;
p1. x = ( l ong) ( c. x - k * _si n) ;p1. y = ( l ong) ( c. y + k * _cos) ;
p2. x = ( l ong) ( c. x + k * _si n) ;p2. y = ( l ong) ( c. y - k * _cos) ;
p3. x = ( l ong) ( c. x + 2. 5* k * _cos) ;p3. y = ( l ong) ( c. y + 2. 5* k * _si n) ;
i f ( pVi ew- >m_pt Sel ect i on. Fi nd( &m_poi nt s[ i ] ) ){
r ect . Set Rect ( m_poi nt s[ i ] . x, m_poi nt s[ i ] . y, m_poi nt s[ i ] . x, m_poi nt s[ i ] . y) ;r ect . I nf l at eRect ( 3, 3) ;pDC- >El l i pse( r ect ) ;
}
}}
pDC- >Sel ect Obj ect ( pOr i gi nal Pen) ;}
voi d CDr awAr c: : MoveTo( CSFCVi ew* pVi ew, CPoi nt del t a){/ / CRect r ect Save1, r ect Save2;
pVi ew- >I nval Ar c( t hi s, m_nPoi nt s- 1) ;
f or ( i nt i =0; i <m_nPoi nt s; i ++)i f ( pVi ew- >m_pt Sel ect i on. Fi nd( &( m_poi nt s[ i ] ) ) )
#i f ! def i ned( AFX_DRAWOBJ_H__39DB6114_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)#def i ne AFX_DRAWOBJ_H__39DB6114_E601_11D2_B1B8_EDD329A68936__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
/ / #i ncl ude ’ ’ Dr awAr c. h’ ’
#def i ne MAX_PARALLEL 10
enum Obj Type { PhObj , Tr Obj , Ar Obj , SELECT, PARALLEL, CONVERGENCE, SYNCRO} ;
cl ass CSFCDoc;cl ass CSFCVi ew;
cl ass CDr awObj : publ i c CObj ect{
DECLARE_SERI AL( CDr awObj ) ;
publ i c:
/ / const r uct or / dest r uct orvi r t ual ~CDr awObj ( ) ;CDr awObj ( ) ;CDr awObj ( Obj Type t ype) ;
/ / member f unct i onsvi r t ual i nt Hi t Test ( CPoi nt poi nt ) ;v i r t ual voi d Dr awI t em( CSFCVi ew* pVi ew, CDC* pDC) ;vi r t ual BOOL Check( i nt &war , i nt & er r ) ;v i r t ual CSt r i ng Text ual For m( ) ;v i r t ual i nt maxCount ( ) ;v i r t ual voi d AddPoi nt ( const CPoi nt & poi nt ) ;v i r t ual voi d Expand( bool det ai l ed) ;v i r t ual voi d Dr awDet ai l s( CSFCVi ew * pVi ew, CDC * pDC) ;vi r t ual voi d Ser i al i ze ( CAr chi ve&) ;vi r t ual voi d OnEdi t Pr oper t y( CSFCVi ew * pVi ew) ;vi r t ual voi d Sel ect I t em( CSFCVi ew* pVi ew) ;vi r t ual CPoi nt Get Handl e( i nt count , CDr awObj * * pAr c) ;v i r t ual CDr awObj * Eval uat eUpper Li nk( CSFCVi ew* pVi ew, i nt * i , i nt j ) ;v i r t ual CDr awObj * Eval uat eLower Li nk( CSFCVi ew* pVi ew, i nt * i , i nt j ) ;v i r t ual voi d Remove( ) ;voi d MoveTo( CPoi nt posi t i on) ;voi d Dr awCi r cl e( CPoi nt cent er , i nt r adi us, CDC* pDC) ;voi d I nval i dat e( CSFCVi ew * pVi ew) ;
/ / member var i abl esObj Type m_Type;CRect m_r ect ;CPoi nt m_posi t i on;i nt n_SFC;i nt m_absol ut e;
/ / l i nksCDr awObj * m_Upper [ MAX_PARALLEL] ;CDr awObj * m_Lower [ MAX_PARALLEL] ;i nt m_nUpper Li nk;i nt m_nLower Li nk;
} ;
#endi f / / ! def i ned( AFX_DRAWOBJ_H__39DB6114_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)
voi d CDr awObj : : Dr awI t em( CSFCVi ew* pVi ew, CDC * pDC){}
i nt CDr awObj : : Hi t Test ( CPoi nt poi nt ){
CDr awObj * t emp;
146
i f ( Get Handl e( 20, &t emp) == poi nt )r et ur n 20;
i f ( Get Handl e( 30, &t emp) == poi nt )r et ur n 30;
i f ( m_r ect . Pt I nRect ( CPoi nt ( poi nt . x* m_gr i d, poi nt . y* m_gr i d) ) )r et ur n 1;
r et ur n 0;}
voi d CDr awObj : : I nval i dat e( CSFCVi ew * pVi ew){
ASSERT_VALI D( t hi s) ;
pVi ew- >Get Document ( ) - >Updat eAl l Vi ews( NULL, HI NT_UPDATE_DRAWOBJ, t hi s) ;}
voi d CDr awObj : : AddPoi nt ( const CPoi nt & poi nt ){/ / v i r t ual f unct i on f or t he ar ct ool cl ass}
voi d CDr awObj : : MoveTo( CPoi nt posi t i on){
ASSERT_VALI D( t hi s) ;CPoi nt t emp=posi t i on;
i f ( posi t i on == m_posi t i on)r et ur n;
CPoi nt of f ( ( t emp. x - m_posi t i on. x) * m_gr i d, ( t emp. y - m_posi t i on. y) * m_gr i d) ;m_r ect . Of f set Rect ( of f ) ;m_posi t i on = t emp;
}
voi d CDr awObj : : Remove( ){
del et e t hi s;}
/ / f i r st par amet er : l i nked number ./ / second par amet er : l i nki ng number .CDr awObj * CDr awObj : : Eval uat eUpper Li nk( CSFCVi ew * pVi ew, i nt * i , i nt j ){
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * pObj Li nked;CDr awObj * t emp;
whi l e ( pos ! = NULL){
pObj Li nked = pObj Li st - >Get Next ( pos) ;i f ( pObj Li nked ! = t hi s){
i nt h = pObj Li nked- >Hi t Test ( Get Handl e( 20+j , &t emp) ) ;i f ( h >= 30 )
i f ( ! pObj Li nked- >m_Lower [ h- 30] ){
* i = h- 30;r et ur n pObj Li nked;
}}
}
147
r et ur n NULL;}
/ / f i r st par amet er : l i nked number ./ / second par amet er : l i nki ng number .CDr awObj * CDr awObj : : Eval uat eLower Li nk( CSFCVi ew * pVi ew, i nt * i , i nt j ){
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * pObj Li nked;CDr awObj * t emp;
whi l e ( pos ! = NULL){
pObj Li nked = pObj Li st - >Get Next ( pos) ;i f ( pObj Li nked ! = t hi s){
i nt h = pObj Li nked- >Hi t Test ( Get Handl e( 30+j , &t emp) ) ;i f ( ( h >= 20) && ( h < 30) )
i f ( ! pObj Li nked- >m_Upper [ h- 20] ){
* i = h- 20;r et ur n pObj Li nked;
}}
}r et ur n NULL;
}
CPoi nt CDr awObj : : Get Handl e( i nt count , CDr awObj * * pAr c){
ASSERT_VALI D ( t hi s) ;
CPoi nt cent er = m_posi t i on;CSi ze si ze = m_r ect . Si ze( ) ;
swi t ch ( count ) {case 1:
r et ur n m_posi t i on;br eak;
case 20:{
* pAr c = m_Upper [ 0] ;r et ur n 0;
}br eak;
case 30:{
* pAr c = m_Lower [ 0] ;r et ur n CSFCVi ew: : Near est OnGr i d( cent er + CPoi nt ( 0, si ze. cy/ 2) ) ;
}br eak;
}r et ur n NULL;
}
voi d CDr awObj : : Sel ect I t em( CSFCVi ew * pVi ew){
}
voi d CDr awObj : : Dr awCi r cl e( CPoi nt cent er , i nt r adi us, CDC * pDC){
CRect r ect ;r ect . Set Rect ( cent er . x- r adi us, cent er . y- r adi us,
cent er . x+r adi us, cent er . y+r adi us) ;
148
pDC- >El l i pse( r ect ) ;}
voi d CDr awObj : : OnEdi t Pr oper t y( CSFCVi ew * pVi ew){
}
voi d CDr awObj : : Ser i al i ze( CAr chi ve& ar ){
CObj ect : : Ser i al i ze( ar ) ;i f ( ar . I sSt or i ng( ) ){
ar << m_absol ut e;ar << m_posi t i on;ar << m_r ect ;ar << ( WORD) m_Type;ar << m_nUpper Li nk;ar << m_nLower Li nk;
}el se{
WORD wTemp;ar >> m_absol ut e;ar >> m_posi t i on;ar >> m_r ect ;ar >> wTemp; m_Type = ( Obj Type) wTemp;ar >> m_nUpper Li nk;ar >> m_nLower Li nk;
}}
voi d CDr awObj : : Dr awDet ai l s( CSFCVi ew * pVi ew, CDC * pDC){
}
voi d CDr awObj : : Expand( bool det ai l ed){
}
i nt CDr awObj : : maxCount ( ){
r et ur n 0;}
CSt r i ng CDr awObj : : Text ual For m( ){
r et ur n ’ ’ ’ ’ ;}
BOOL CDr awObj : : Check( i nt & war , i nt & er r ){
r et ur n TRUE;}
149
classCGraph
File : Graph.h/ / Gr aph. h: i nt er f ace f or t he CGr aph cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_GRAPH_H__D82BE9E9_71CC_11D3_8FB1_C574580D6068__I NCLUDED_)#def i ne AFX_GRAPH_H__D82BE9E9_71CC_11D3_8FB1_C574580D6068__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#def i ne STEP 1#def i ne I NI TI AL_STEP 2#def i ne END_STEP 3#def i ne TRANSI TI ON 4#def i ne ASSI GNMENT 5#def i ne SFC 6#def i ne END_SFC 7#def i ne BEGI N_PROJECT 8#def i ne END_PROJECT 9#def i ne FROM 10#def i ne TO 11#def i ne END 12
st r uct node {i nt number ;BOOL pl aced;BOOL count ed;CPoi nt posi t i on;i nt wi dt h;CLi st <st r uct node * , st r uct node * > down;CLi st <st r uct node * , st r uct node * > up;
} ;
c l ass CGr aph{publ i c:
/ / member f unct i onsCSt r i ng Ext r act Qual ( CSt r i ng qual , CTi mer * t m) ;BOOL Bui l dPr j ( char * pBuf , DWORD l engt h) ;voi d Sor t ByX( st r uct node* pNode) ;BOOL Comput eFr omBot t om( st r uct node * pNode) ;BOOL I nser t Fr omBot t om( st r uct node * pNode) ;CDr awObj * f i ndSt ep( i nt n) ;CDr awObj * f i ndTr ans( i nt n) ;UI NT LookUpToken( char * s) ;BOOL Bui l dGr aph( char * pBuf , DWORD l engt h) ;CGr aph( ) ;vi r t ual ~CGr aph( ) ;
} ;
#endi f / / ! def i ned( AFX_GRAPH_H__D82BE9E9_71CC_11D3_8FB1_C574580D6068__I NCLUDED_)
File : Graph.cpp/ / Gr aph. cpp: i mpl ement at i on of t he CGr aph cl ass./ /
ASSERT( pBuf ! = NULL) ;char * p_buf cpy = ( char * ) mal l oc( l engt h) ;
memcpy( p_buf cpy, pBuf , l engt h) ;
char * s;i nt num, t ok;CSt r i ng name;BOOL f i ni shed = FALSE;char seps[ ] = ’ ’ \ t \ n; ’ ’ ;
s = st r t ok( p_buf cpy, ’ ’ \ n\ t : ’ ’ ) ;t ok = LookUpToken( s) ;ASSERT( t ok == SFC) ;s = st r t ok( NULL, ’ ’ \ n\ t : ’ ’ ) ;sscanf ( s, ’ ’ %i ’ ’ , &num) ;ASSERT( ( num <= 9) && ( num >= 1) ) ;CDr awObj Li st * pNewLi st = new ( CDr awObj Li st ) ;Gl obObj Li st Map[ num] = pNewLi st ;pObj Li st = pNewLi st ;s = st r t ok( NULL, ’ ’ \ t \ n; ’ ’ ) ;name. For mat ( ’ ’ %s’ ’ , s) ;names[ num] = name;pFr ame- >AddSFC( num) ;
s = st r t ok( NULL, seps) ;
whi l e ( ! f i ni shed){
/ / Whi l e t her e ar e t okens i n ’ ’ p_buf cpy’ ’t ok = LookUpToken( s) ;swi t ch ( t ok) {case STEP:
{CSt r i ng name;CSt r i ng qual ;
152
CTi mer t m;s = st r t ok( NULL, seps) ;ASSERT ( * s == ’ S’ ) ;s++;sscanf ( s, ’ ’ %i ’ ’ , &num) ;ASSERT( ( num >= 100) & ( num <= 999) ) ;s = st r t ok( NULL, seps) ;ASSERT ( * s == ’ : ’ ) ;s = st r t ok( NULL, ’ ’ ( ’ ’ ) ;name. For mat ( ’ ’ %s’ ’ , s) ;s = st r t ok( NULL, ’ ’ ) ’ ’ ) ;/ / check! ASSERT ( s i s a qual i f i er ) ;qual . For mat ( ’ ’ %s’ ’ , s) ;qual = Ext r act Qual ( qual , &t m) ;s = st r t ok( NULL, ’ ’ ’ ’ ) ;ASSERT ( * s = ’ : ’ ) ;s = st r t ok( NULL, ’ ’ ; ’ ’ ) ;ASSERT ( LookUpToken( s) == END_STEP) ;
/ / i nser t el ement .CPhaseObj * NewObj = new CPhaseObj ( CPoi nt ( 5, 5) , FALSE) ;NewObj - >m_number = num % 100;NewObj - >m_name = name;NewObj - >m_qual i f i er = qual ;NewObj - >m_t i me. d = t m. d;NewObj - >m_t i me. h = t m. h;NewObj - >m_t i me. m = t m. m;NewObj - >m_t i me. s = t m. s;NewObj - >m_t i me. ms = t m. ms;
pObj Li st - >AddTai l ( NewObj ) ;}br eak;case I NI TI AL_STEP:{
CSt r i ng name;CSt r i ng qual ;CTi mer t m;s = st r t ok( NULL, seps) ;ASSERT ( * s == ’ S’ ) ;s++;sscanf ( s, ’ ’ %i ’ ’ , &num) ;ASSERT( ( num >= 100) & ( num <= 999) ) ;s = st r t ok( NULL, seps) ;ASSERT ( * s == ’ : ’ ) ;s = st r t ok( NULL, ’ ’ ( ’ ’ ) ;name. For mat ( ’ ’ %s’ ’ , s) ;s = st r t ok( NULL, ’ ’ ) ’ ’ ) ;/ / check! ASSERT ( s i s a qual i f i er ) ;qual . For mat ( ’ ’ %s’ ’ , s) ;qual = Ext r act Qual ( qual , &t m) ;s = st r t ok( NULL, ’ ’ ’ ’ ) ;ASSERT ( * s = ’ : ’ ) ;s = st r t ok( NULL, ’ ’ ; ’ ’ ) ;ASSERT ( LookUpToken( s) == END_STEP) ;
/ / i nser t el ement .CPhaseObj * NewObj = new CPhaseObj ( CPoi nt ( 5, 5) , TRUE) ;NewObj - >m_number = num % 100;NewObj - >m_name = name;NewObj - >m_qual i f i er = qual ;NewObj - >m_t i me. d = t m. d;NewObj - >m_t i me. h = t m. h;NewObj - >m_t i me. m = t m. m;NewObj - >m_t i me. s = t m. s;
153
NewObj - >m_t i me. ms = t m. ms;
pObj Li st - >AddTai l ( NewObj ) ;}br eak;case TRANSI TI ON:{
CSt r i ng name;s = st r t ok( NULL, seps) ;ASSERT ( * s == ’ T’ ) ;s++;sscanf ( s, ’ ’ %i ’ ’ , &num) ;ASSERT( ( num >= 100) & ( num <= 999) ) ;s = st r t ok( NULL, seps) ;ASSERT ( LookUpToken( s) == FROM) ;s = st r t ok( NULL, seps) ;
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / s cont ai ns ’ f r om’s = st r t ok( NULL, seps) ;ASSERT ( LookUpToken( s) == TO) ;s = st r t ok( NULL, seps) ;
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / s cont ai ns ’ t o’s = st r t ok( NULL, seps) ;ASSERT ( LookUpToken( s) == ASSI GNMENT) ;s = st r t ok( NULL, ’ ’ ; ’ ’ ) ;name. For mat ( ’ ’ %s’ ’ , s) ;
/ / i nser t el ement .CTr ansObj * NewObj = new CTr ansObj ( CPoi nt ( 8, 8) ) ;NewObj - >m_number = num % 100;NewObj - >m_condi t i on = name;
pObj Li st - >AddTai l ( NewObj ) ;}br eak;case END_SFC:{
f i ni shed = TRUE;}br eak;
}/ * Get next t oken: * /s = st r t ok( NULL, ’ ’ \ t \ n ; ’ ’ ) ;
}
CDr awObj * pObj ;
CMap <i nt , i nt , st r uct node * , st r uct node * > St epLi st ;CMap <i nt , i nt , st r uct node * , st r uct node * > Tr ansLi st ;
/ / f i r st al l oc al l nodesPOSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;
i f ( pObj - >m_Type == PhObj ){
154
st r uct node * pNode = new ( st r uct node) ;CPhaseObj * pSt ep = ( CPhaseObj * ) pObj ;pNode- >count ed = FALSE;pNode- >pl aced = FALSE;pNode- >number = pSt ep- >m_number ;pNode- >wi dt h = 2;St epLi st [ pSt ep- >m_number ] = pNode;
}
el se i f ( pObj - >m_Type == Tr Obj ){
st r uct node * pNode = new ( st r uct node) ;CTr ansObj * pTr ans = ( CTr ansObj * ) pObj ;pNode- >pl aced = FALSE;pNode- >count ed = FALSE;pNode- >number = pTr ans- >m_number ;pNode- >wi dt h = 2;Tr ansLi st [ pTr ans- >m_number ] = pNode;
memcpy( p_buf cpy, pBuf , l engt h) ;s = st r t ok( p_buf cpy, seps) ;
whi l e( s ! = NULL ){
/ * Whi l e t her e ar e t okens i n ’ ’ p_buf cpy’ ’ * /t ok = LookUpToken( s) ;i f ( t ok == TRANSI TI ON){
s = st r t ok( NULL, ’ ’ ’ ’ ) ;ASSERT( * s == ’ T’ ) ;s++;sscanf ( s, ’ ’ %i ’ ’ , &num) ;num = num % 100;pNode = Tr ansLi st [ num] ;ASSERT( pNode) ;s = st r t ok( NULL, seps) ;ASSERT ( LookUpToken( s) == FROM) ;s = st r t ok( NULL, ’ ’ , ( ’ ’ ) ;/ / s cont ai ns ’ f r om’whi l e ( * s == ’ S’ ){
s++;sscanf ( s, ’ ’ %i ’ ’ , &num) ;num = num % 100;pLi nk = St epLi st [ num] ;ASSERT( pLi nk) ;/ / cr eat e a doubl e l i nk!pNode- >up. AddTai l ( pLi nk) ;pLi nk- >down. AddTai l ( pNode) ;s = st r t ok( NULL, ’ ’ , ) ’ ’ ) ;
}ASSERT ( LookUpToken( s) == TO) ;s = st r t ok( NULL, ’ ’ , ( ’ ’ ) ;/ / s cont ai ns ’ t o’whi l e ( * s == ’ S’ ){
s++;
155
sscanf ( s, ’ ’ %i ’ ’ , &num) ;num = num % 100;pLi nk = St epLi st [ num] ;ASSERT( pLi nk) ;/ / cr eat e a doubl e l i nk!pNode- >down. AddTai l ( pLi nk) ;pLi nk- >up. AddTai l ( pNode) ;
s = st r t ok( NULL, ’ ’ , ) ’ ’ ) ;}ASSERT ( LookUpToken( s) == ASSI GNMENT) ;s = st r t ok( NULL, ’ ’ ; ’ ’ ) ;
}s = st r t ok( NULL, seps) ;
}/ / t he gr aph i s compl et e!
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / / l ook f or an i ni t i al st ep:
pos = pObj Li st - >Get HeadPosi t i on( ) ;BOOL f ound = FALSE;
whi l e ( ( ! f ound) && ( pos ! = NULL) ){
pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type == PhObj ){
CPhaseObj * pSt ep = ( CPhaseObj * ) pObj ;f ound = ( ( pSt ep- >m_i ni t i al ) && ( pSt ep- >m_number = 1) ) ;i f ( f ound)
pNode = St epLi st [ pSt ep- >m_number ] ;}
}ASSERT ( f ound) ;
/ / pl aci ng f i r st st ep!pNode- >wi dt h = 2;pNode- >count ed = TRUE;
pos = pObj Li st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;
i f ( pObj - >m_Type == PhObj ){
CPhaseObj * pSt ep = ( CPhaseObj * ) pObj ;pNode = St epLi st [ pSt ep- >m_number ] ;Sor t ByX( pNode) ;nDownLi nk = pNode- >down. Get Count ( ) ;i f ( nDownLi nk == 1){
/ / s i mpl y l i nkst r uct node * pNodeLi nk = pNode- >down. Get Head( ) ;i f ( pNodeLi nk- >up. Get Count ( ) == 1){
num = pNodeLi nk- >number ;CDr awObj * pLi nkObj = f i ndTr ans( num) ;ASSERT( pLi nkObj ) ;CAr cTool : : OnNewAr c( pObj , pLi nkObj , 0, 0) ;
}}el se i f ( nDownLi nk > 1){
/ / sel ectCPoi nt col l oc( pNode- >posi t i on. x, pNode- >posi t i on. y+3) ;CMul t i Obj * pNewObj = new CMul t i Obj ( col l oc, SELECT,
nDownLi nk, pNode- >wi dt h* 2) ;pObj Li st - >AddTai l ( pNewObj ) ;CAr cTool : : OnNewAr c( pObj , pNewObj , 0, 0) ;
POSI TI ON pos_l i nk = pNode- >down. Get HeadPosi t i on( ) ;
161
st r uct node * pNodeLi nk;i = 0;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >down. Get Next ( pos_l i nk) ;CDr awObj * pLi nkObj = f i ndTr ans( pNodeLi nk- >number ) ;ASSERT ( pLi nkObj ) ;CAr cTool : : OnNewAr c( pNewObj , pLi nkObj , i , 0) ;i ++;
}}nUpLi nk = pNode- >up. Get Count ( ) ;i f ( nUpLi nk > 1){
/ / conver gencei nt mi n = 10000, max = - 10000;POSI TI ON pos_l i nk = pNode- >up. Get HeadPosi t i on( ) ;st r uct node * pNodeLi nk;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >up. Get Next ( pos_l i nk) ;i f ( mi n > pNodeLi nk- >posi t i on. x)
mi n = pNodeLi nk- >posi t i on. x;i f ( max < pNodeLi nk- >posi t i on. x)
max = pNodeLi nk- >posi t i on. x;}CPoi nt col l oc = CPoi nt ( ( mi n+max) / 2, pNode- >posi t i on. y- 3) ;i nt w = ( max- mi n) / ( 2* ( nUpLi nk- 1) ) ;i f ( w<2)
w = 2;CMul t i Obj * pNewObj = new CMul t i Obj ( col l oc, CONVERGENCE,
nUpLi nk, w) ;pObj Li st - >AddTai l ( pNewObj ) ;CAr cTool : : OnNewAr c( pNewObj , pObj , 0, 0) ;
pos_l i nk = pNode- >up. Get HeadPosi t i on( ) ;i = 0;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >up. Get Next ( pos_l i nk) ;CDr awObj * pLi nkObj = f i ndTr ans( pNodeLi nk- >number ) ;ASSERT ( pLi nkObj ) ;CAr cTool : : OnNewAr c( pLi nkObj , pNewObj , 0, i ) ;i ++;
}}
}
i f ( pObj - >m_Type == Tr Obj ){
CTr ansObj * pTr ans = ( CTr ansObj * ) pObj ;pNode = Tr ansLi st [ pTr ans- >m_number ] ;Sor t ByX( pNode) ;nDownLi nk = pNode- >down. Get Count ( ) ;i f ( nDownLi nk == 1){
/ / s i mpl y l i nkst r uct node * pNodeLi nk = pNode- >down. Get Head( ) ;i f ( pNodeLi nk- >up. Get Count ( ) == 1){
num = pNodeLi nk- >number ;CDr awObj * pLi nkObj = f i ndSt ep( num) ;ASSERT( pLi nkObj ) ;CAr cTool : : OnNewAr c( pObj , pLi nkObj , 0, 0) ;
}
162
}el se i f ( nDownLi nk > 1){
/ / par al l elst r uct node * pNodeLi nk;CPoi nt col l oc( pNode- >posi t i on. x, pNode- >posi t i on. y+2) ;CMul t i Obj * pNewObj = new CMul t i Obj ( col l oc, PARALLEL,
nDownLi nk, pNode- >wi dt h* 2) ;pObj Li st - >AddTai l ( pNewObj ) ;CAr cTool : : OnNewAr c( pObj , pNewObj , 0, 0) ;
POSI TI ON pos_l i nk = pNode- >down. Get HeadPosi t i on( ) ;i = 0;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >down. Get Next ( pos_l i nk) ;CDr awObj * pLi nkObj = f i ndSt ep( pNodeLi nk- >number ) ;ASSERT ( pLi nkObj ) ;CAr cTool : : OnNewAr c( pNewObj , pLi nkObj , i , 0) ;i ++;
}}nUpLi nk = pNode- >up. Get Count ( ) ;i f ( nUpLi nk > 1){
/ / syncr oi nt mi n = 10000, max = - 10000;POSI TI ON pos_l i nk = pNode- >up. Get HeadPosi t i on( ) ;st r uct node * pNodeLi nk;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >up. Get Next ( pos_l i nk) ;i f ( pNodeLi nk- >posi t i on. x < mi n)
mi n = pNodeLi nk- >posi t i on. x;i f ( pNodeLi nk- >posi t i on. x > max)
max = pNodeLi nk- >posi t i on. x;}CPoi nt col l oc = CPoi nt ( ( mi n+max) / 2, pNode- >posi t i on. y- 2) ;i nt w = ( max- mi n) / ( 2* ( nUpLi nk- 1) ) ;i f ( w<2)
w = 2;CMul t i Obj * pNewObj = new CMul t i Obj ( col l oc, SYNCRO,
nUpLi nk, w) ;pObj Li st - >AddTai l ( pNewObj ) ;CAr cTool : : OnNewAr c( pNewObj , pObj , 0, 0) ;
pos_l i nk = pNode- >up. Get HeadPosi t i on( ) ;i = 0;whi l e ( pos_l i nk ! = NULL){
pNodeLi nk = pNode- >up. Get Next ( pos_l i nk) ;CDr awObj * pLi nkObj = f i ndSt ep( pNodeLi nk- >number ) ;ASSERT ( pLi nkObj ) ;CAr cTool : : OnNewAr c( pLi nkObj , pNewObj , 0, i ) ;i ++;
}}
}
}
f r ee( p_buf cpy) ;
r et ur n TRUE;
163
}
UI NT CGr aph: : LookUpToken( char * s){
st r uct t okens {char t oken[ 20] ;char t ok;
} t abl e[ ] = {’ ’ I NI TI AL_STEP’ ’ , I NI TI AL_STEP,’ ’ STEP’ ’ , STEP,’ ’ END_STEP’ ’ , END_STEP,’ ’ TRANSI TI ON’ ’ , TRANSI TI ON,’ ’ : =’ ’ , ASSI GNMENT,’ ’ SFC’ ’ , SFC,’ ’ END_SFC’ ’ , END_SFC,’ ’ BEGI N_PROJECT’ ’ , BEGI N_PROJECT,’ ’ END_PROJECT’ ’ , END_PROJECT,’ ’ FROM’ ’ , FROM,’ ’ TO’ ’ , TO,’ ’ ’ ’ , END
} ;
i nt i ;f or ( i =0; * t abl e[ i ] . t oken; i ++)
i f ( ! st r cmp( t abl e[ i ] . t oken, s) )r et ur n t abl e[ i ] . t ok;
r et ur n 0; / / unknow command !
}
CDr awObj * CGr aph: : f i ndTr ans( i nt n){
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;BOOL f ound = FALSE;CDr awObj * pObj ;whi l e ( ( ! f ound) && ( pos ! = NULL) ){
pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type == Tr Obj ){
BOOL CGr aph: : I nser t Fr omBot t om( st r uct node * pNode){
BOOL i nser t ed = FALSE;i f ( pNode ! = NULL){
i nt nUpLi nk = pNode- >up. Get Count ( ) ;i f ( nUpLi nk > 1){
POSI TI ON pos = pNode- >up. Get HeadPosi t i on( ) ;BOOL val i d = TRUE;st r uct node * t emp;whi l e ( pos ! = NULL){
t emp = pNode- >up. Get Next ( pos) ;val i d = val i d && ( t emp- >pl aced) ;
}i nt sx = 10000, dx = - 10000, h = - 10000;pos = pNode- >up. Get HeadPosi t i on( ) ;whi l e ( ( pos ! = NULL) && val i d){
t emp = pNode- >up. Get Next ( pos) ;CPoi nt _pos = t emp- >posi t i on;i f ( _pos. x < sx)
sx = _pos. x;i f ( _pos. x > dx)
dx = _pos. x;i f ( _pos. y > h)
h = _pos. y;}i f ( val i d){
pNode- >posi t i on = CPoi nt ( ( sx+dx) / 2, h+5) ;pNode- >pl aced = TRUE;i nser t ed = TRUE;
}}
}
r et ur n i nser t ed;}
BOOL CGr aph: : Comput eFr omBot t om( st r uct node * pNode){
BOOL count = FALSE;i f ( pNode ! = NULL){
i nt nUpLi nk = pNode- >up. Get Count ( ) ;i f ( nUpLi nk > 1){
POSI TI ON pos = pNode- >up. Get HeadPosi t i on( ) ;BOOL val i d = TRUE;st r uct node * t emp;whi l e ( pos ! = NULL){
t emp = pNode- >up. Get Next ( pos) ;val i d = val i d && ( t emp- >count ed) ;
165
}i f ( val i d){
pNode- >wi dt h = 2;pNode- >count ed = TRUE;count = TRUE;
}}
}
r et ur n count ;
}
voi d CGr aph: : Sor t ByX( st r uct node * pNode){
i nt i =0;POSI TI ON mi n;i nt num = pNode- >down. Get Count ( ) ;
st r uct node * Ar r ayNode[ 10] ;
st r uct node * pLi nkNode;whi l e ( pNode- >down. Get Count ( ) > 0){
st r uct node * pMi nLi nk;i nt posxmi n = 10000;POSI TI ON pos = pNode- >down. Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
pLi nkNode = pNode- >down. Get Next ( pos) ;i f ( pLi nkNode- >posi t i on. x < posxmi n){
posxmi n = pLi nkNode- >posi t i on. x;pMi nLi nk = pLi nkNode;
}}Ar r ayNode[ i ] = pMi nLi nk;i ++;mi n = pNode- >down. Fi nd( pMi nLi nk) ;ASSERT ( mi n) ;pNode- >down. RemoveAt ( mi n) ;
}
f or ( i =0; i <num; i ++)pNode- >down. AddTai l ( Ar r ayNode[ i ] ) ;
i = 0;num = pNode- >up. Get Count ( ) ;st r uct node * Ar r ayNode2[ 10] ;whi l e ( pNode- >up. Get Count ( ) > 0){
st r uct node * pMi nLi nk;i nt posxmi n = 10000;POSI TI ON pos = pNode- >up. Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
pLi nkNode = pNode- >up. Get Next ( pos) ;i f ( pLi nkNode- >posi t i on. x < posxmi n){
posxmi n = pLi nkNode- >posi t i on. x;pMi nLi nk = pLi nkNode;
166
}}Ar r ayNode2[ i ] = pMi nLi nk;i ++;mi n = pNode- >up. Fi nd( pMi nLi nk) ;ASSERT ( mi n) ;pNode- >up. RemoveAt ( mi n) ;
}
f or ( i =0; i <num; i ++)pNode- >up. AddTai l ( Ar r ayNode2[ i ] ) ;
}
CSt r i ng CGr aph: : Ext r act Qual ( CSt r i ng qual , CTi mer * t m){
CSt r i ng name;i nt p = qual . Fi nd( ’ , ’ ) ;i f ( p ! = - 1){
name = qual . Lef t ( p) ;CSt r i ng t i me = qual . Ri ght ( qual . Get Lengt h( ) - p- 1) ;( * t m) . St r i ng2Ti me( t i me) ;
}el se{
name = qual ;( * t m) . d = 0;( * t m) . h = 0;( * t m) . m = 0;( * t m) . s = 0;( * t m) . ms = 0;
}
r et ur n name;}
classCMainFrame
File : MainFrm.h/ / Mai nFr m. h : i nt er f ace of t he CMai nFr ame cl ass/ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_MAI NFRM_H__39DB6108_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)#def i ne AFX_MAI NFRM_H__39DB6108_E601_11D2_B1B8_EDD329A68936__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CMai nFr ame : publ i c CFr ameWnd{pr ot ect ed: / / cr eat e f r om ser i al i zat i on onl y
CMai nFr ame( ) ;DECLARE_DYNCREATE( CMai nFr ame)
/ / At t r i but espubl i c:
167
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CMai nFr ame)vi r t ual BOOL Pr eCr eat eWi ndow( CREATESTRUCT& cs) ;/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpubl i c:
/ / member f unct i onvoi d Updat eWi ndowTi t l e( CSt r i ng pr oj _name) ;voi d AddSFC( i nt n) ;voi d RemoveAl l SFC( ) ;voi d RemoveSFC( i nt n) ;vi r t ual ~CMai nFr ame( ) ;BOOL Cr eat eTabBar ( ) ;
/ / member var i abl esCDi al ogBar m_wndTabBar ;
#i f def _DEBUGvi r t ual voi d Asser t Val i d( ) const ;vi r t ual voi d Dump( CDumpCont ext & dc) const ;
#endi f
pr ot ect ed: / / cont r ol bar embedded member sCSt at usBar m_wndSt at usBar ;CTool Bar m_wndTool Bar ;
/ / Gener at ed message map f unct i onspr ot ect ed:
/ / { { AFX_MSG( CMai nFr ame)af x_msg i nt OnCr eat e( LPCREATESTRUCT l pCr eat eSt r uct ) ;af x_msg voi d OnSi ze( UI NT nType, i nt cx, i nt cy) ;af x_msg voi d OnSFCSel change( NMHDR* pNMHDR, LRESULT* pResul t ) ;af x_msg voi d OnEdi t Sf cName( ) ;/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_MAI NFRM_H__39DB6108_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)
File : MainFrm.cpp/ / Mai nFr m. cpp : i mpl ement at i on of t he CMai nFr ame cl ass/ /
/ / TODO: add member i ni t i al i zat i on code her e
}
CMai nFr ame: : ~CMai nFr ame( ){}
BOOL CMai nFr ame: : Cr eat eTabBar ( ){
CTabCt r l * pCTab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;CSt r i ng TabTxt = ’ ’ SFC 1 - ’ ’ ;TabTxt += ’ ’ NoName’ ’ ;TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_TEXT | TCI F_PARAM;TabCt r l I t em. pszText = TabTxt . Get Buf f er ( 10) ; / / ’ ’ SFC 1’ ’ ;TabCt r l I t em. l Par am = 1;pCTab- >I nser t I t em( 0, &TabCt r l I t em ) ;
Act i veSFC = 1;
r et ur n 0;}
i nt CMai nFr ame: : OnCr eat e( LPCREATESTRUCT l pCr eat eSt r uct ){
i f ( CFr ameWnd: : OnCr eat e( l pCr eat eSt r uct ) == - 1)
169
r et ur n - 1;
i f ( ! m_wndTool Bar . Cr eat e( t hi s) | |! m_wndTool Bar . LoadTool Bar ( I DR_MAI NFRAME) )
{TRACE0( ’ ’ Fai l ed t o cr eat e t ool bar \ n’ ’ ) ;r et ur n - 1; / / f ai l t o cr eat e
}
i f ( ! m_wndTabBar . Cr eat e( t hi s, I DD_DI ALOGBAR,CBRS_TOP, I DD_DI ALOGBAR) )
{TRACE0( ’ ’ Fai l ed t o cr eat e Dl gBar \ n’ ’ ) ;r et ur n - 1; / / f ai l t o cr eat e
}Cr eat eTabBar ( ) ;
i f ( ! m_wndSt at usBar . Cr eat e( t hi s) | |! m_wndSt at usBar . Set I ndi cat or s( i ndi cat or s,
si zeof ( i ndi cat or s) / s i zeof ( UI NT) ) ){
TRACE0( ’ ’ Fai l ed t o cr eat e st at us bar \ n’ ’ ) ;r et ur n - 1; / / f ai l t o cr eat e
}
/ / TODO: Remove t hi s i f you don’ t want t ool t i ps or a r esi zeabl e t ool barm_wndTool Bar . Set Bar St yl e( m_wndTool Bar . Get Bar St yl e( ) |
CBRS_TOOLTI PS | CBRS_FLYBY | CBRS_SI ZE_DYNAMI C) ;/ *
/ / TODO: Del et e t hese t hr ee l i nes i f you don’ t want t he t ool bar t o/ / be dockabl em_wndTool Bar . Enabl eDocki ng( CBRS_ALI GN_ANY) ;Enabl eDocki ng( CBRS_ALI GN_ANY) ;DockCont r ol Bar ( &m_wndTool Bar ) ;
voi d CMai nFr ame: : OnSi ze( UI NT nType, i nt cx, i nt cy){
CFr ameWnd: : OnSi ze( nType, cx, cy) ;
i nt i =1;/ / TODO: Add your message handl er code her e
i f ( m_wndTabBar . m_hWnd ! = NULL){
CTabCt r l * pCTab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;
i f ( pCTab ! = NULL){
CRect r ect ;m_wndTabBar . Get Cl i ent Rect ( r ect ) ;pCTab- >MoveWi ndow( r ect . TopLef t ( ) . x, r ect . TopLef t ( ) . y,r ect . Wi dt h( ) , r ect . Hei ght ( ) , TRUE) ;
}}
}
voi d CMai nFr ame: : OnSFCSel change( NMHDR* pNMHDR, LRESULT* pResul t ){
CDocument * pDoc = Get Act i veDocument ( ) ;CTabCt r l * t ab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_PARAM;
t ab- >Get I t em( t ab- >Get Cur Sel ( ) , &TabCt r l I t em ) ;
i nt t abSel = ( i nt ) TabCt r l I t em. l Par am;
CDr awObj Li st * pSel Li st ;pSel Li st = ( CDr awObj Li st * ) Gl obObj Li st Map[ t abSel ] ;
ASSERT ( pSel Li st ! = NULL) ;pObj Li st = pSel Li st ;
Act i veSFC = ( i nt ) t abSel ;
pDoc- >Updat eAl l Vi ews( NULL) ;}
voi d CMai nFr ame: : RemoveSFC( i nt n){
CDocument * pDoc = Get Act i veDocument ( ) ;CTabCt r l * pTab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_PARAM;
BOOL f ound = FALSE;i nt h = - 1;i nt num = pTab- >Get I t emCount ( ) ;
whi l e ( h <= num && ! f ound){
171
h++;pTab- >Get I t em( h, &TabCt r l I t em ) ;i nt number = ( i nt ) TabCt r l I t em. l Par am;i f ( number == n)
f ound = TRUE;}
i f ( f ound){
num = pTab- >Get I t emCount ( ) ;i f ( num > 0){
pTab- >Del et eI t em( h) ;
pTab- >Get I t em( 0, &TabCt r l I t em) ;i nt t abSel = ( i nt ) TabCt r l I t em. l Par am;
CDr awObj Li st * pSel Li st ;pSel Li st = ( CDr awObj Li st * ) Gl obObj Li st Map[ t abSel ] ;
ASSERT ( pSel Li st ! = NULL) ;
pObj Li st = pSel Li st ;Act i veSFC = ( i nt ) t abSel ;pTab- >Set Cur Sel ( 0) ;
}el se{
Cr eat eTabBar ( ) ;}
}
pDoc- >Updat eAl l Vi ews( NULL) ;}
voi d CMai nFr ame: : RemoveAl l SFC( ){
CTabCt r l * pTab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;i f ( pTab ! = NULL)
pTab- >Del et eAl l I t ems( ) ;
CDocument * pDoc = Get Act i veDocument ( ) ;pDoc- >Updat eAl l Vi ews( NULL) ;
}
voi d CMai nFr ame: : AddSFC( i nt n){
CTabCt r l * pTab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;
i f ( pTab ! = NULL){
CSt r i ng TabTxt = ’ ’ SFC ’ ’ ;CSt r i ng num;num. For mat ( ’ ’ %i - ’ ’ , n) ;TabTxt += num;TabTxt += names[ n] ;TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_TEXT | TCI F_PARAM;TabCt r l I t em. pszText = TabTxt . Get Buf f er ( 10) ; / / ’ ’ SFC 1’ ’ ;TabCt r l I t em. l Par am = n;pTab- >I nser t I t em( 0, &TabCt r l I t em ) ;pTab- >Set Cur Sel ( 0) ;
172
Act i veSFC = n;
}CDocument * pDoc = Get Act i veDocument ( ) ;pDoc- >Updat eAl l Vi ews( NULL) ;
}
voi d CMai nFr ame: : OnEdi t Sf cName( ){
/ / TODO: Add your command handl er code her eCDocument * pDoc = Get Act i veDocument ( ) ;CTabCt r l * t ab = ( CTabCt r l * ) m_wndTabBar . Get Dl gI t em( I DC_TAB) ;
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_PARAM;
t ab- >Get I t em( t ab- >Get Cur Sel ( ) , &TabCt r l I t em ) ;
i nt t abSel = ( i nt ) TabCt r l I t em. l Par am;
CSFCDl g dl g;dl g. m_SFCname = names[ t abSel ] ;i f ( dl g. DoModal ( ) == I DOK){
names[ t abSel ] = dl g. m_SFCname;} ;
TabCt r l I t em. mask = TCI F_TEXT;CSt r i ng TabTxt ;TabTxt . For mat ( ’ ’ SFC %i - ’ ’ , t abSel ) ;TabTxt += names[ t abSel ] ;
TabCt r l I t em. pszText = TabTxt . Get Buf f er ( 10) ;
t ab- >Set I t em( t ab- >Get Cur Sel ( ) , &TabCt r l I t em ) ;
pDoc- >Updat eAl l Vi ews( NULL) ;}
voi d CMai nFr ame: : Updat eWi ndowTi t l e( CSt r i ng pr oj _name){
CSt r i ng st r Ti t l e;
st r Ti t l e = ’ ’ SFC - Pr oj ect : ’ ’ + pr oj _name;
Set Wi ndowText ( st r Ti t l e) ;}
classCMultiObj
File : MultiObj .h/ / Mul t i 1Obj . h: i nt er f ace f or t he CMul t i 1Obj cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_MULTI 1OBJ_H__D6DE3CE2_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_)#def i ne AFX_MULTI 1OBJ_H__D6DE3CE2_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_
173
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Dr awObj . h’ ’
c l ass CMul t i Obj : publ i c CDr awObj{
DECLARE_SERI AL ( CMul t i Obj )
publ i c:/ / member f unct i onsCMul t i Obj ( ) { } ;v i r t ual BOOL Check( i nt & war , i nt & er r ) ;v i r t ual voi d Ser i al i ze( CAr chi ve & ar ) ;v i r t ual voi d OnEdi t Pr oper t y( CSFCVi ew * pVi ew) ;vi r t ual voi d Sel ect I t em( CSFCVi ew * pVi ew) ;vi r t ual i nt Hi t Test ( CPoi nt poi nt ) ;v i r t ual CPoi nt Get Handl e( i nt count , CDr awObj * * pAr c) ;v i r t ual voi d Dr awI t em( CSFCVi ew * pVi ew, CDC * pDC) ;CMul t i Obj ( CPoi nt poi nt , Obj Type t ype) ;CMul t i Obj ( CPoi nt poi nt , Obj Type t ype, i nt n_l nk, i nt spc) ;v i r t ual ~CMul t i Obj ( ) ;
/ / member var i abl ei nt m_space;
f r i end cl ass CMul t i Tool ;} ;
#endi f / / ! def i ned( AFX_MULTI 1OBJ_H__D6DE3CE2_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_)
File : MultiObj .cpp/ / Mul t i 1Obj . cpp: i mpl ement at i on of t he CMul t i 1Obj cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
I MPLEMENT_SERI AL ( CMul t i Obj , CDr awObj , 0)
CMul t i Obj : : CMul t i Obj ( CPoi nt poi nt , Obj Type t ype) : CDr awObj ( t ype){
174
m_posi t i on = poi nt ;
i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
m_nUpper Li nk = 2;m_nLower Li nk = 1;
}i f ( m_Type == SELECT | | m_Type == PARALLEL)
{m_nUpper Li nk = 1;m_nLower Li nk = 2;
}
m_space = 4;
m_r ect . l ef t = poi nt . x* m_gr i d- m_di m* 2;m_r ect . t op = poi nt . y* m_gr i d- m_di m/ 2;m_r ect . r i ght = poi nt . x* m_gr i d+m_di m* 2;m_r ect . bot t om = poi nt . y* m_gr i d+m_di m/ 2;
}
CMul t i Obj : : CMul t i Obj ( CPoi nt poi nt , Obj Type t ype, i nt n_l nk, i nt spc): CDr awObj ( t ype)
{
m_posi t i on = poi nt ;
i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
m_nUpper Li nk = n_l nk;m_nLower Li nk = 1;
}i f ( m_Type == SELECT | | m_Type == PARALLEL)
{m_nUpper Li nk = 1;m_nLower Li nk = n_l nk;
}
m_space = spc;
m_r ect . l ef t = poi nt . x* m_gr i d- m_di m* m_space* ( n_l nk- 1) / 2;m_r ect . r i ght = poi nt . x* m_gr i d+m_di m* m_space* ( n_l nk- 1) / 2;
m_r ect . t op = poi nt . y* m_gr i d- m_di m/ 2;m_r ect . bot t om = poi nt . y* m_gr i d+m_di m/ 2;
}
CMul t i Obj : : ~CMul t i Obj ( ){
}
voi d CMul t i Obj : : Dr awI t em( CSFCVi ew * pVi ew, CDC * pDC){
CPoi nt cent r ( m_posi t i on. x* m_gr i d, m_posi t i on. y* m_gr i d) ;CPen MyPen;CPen * pOr i gi nal Pen;BOOL changed = FALSE;BOOL cor r ect ;
i nt space_bt w_l i nes = m_di m/ 15;i nt l enght 1 = ( m_space* m_di m/ 2) * ( m_nLower Li nk- 1) ;
175
i nt l enght 2 = ( m_space* m_di m/ 2) * ( m_nUpper Li nk- 1) ;
i f ( pVi ew- >bCheck){
i nt t emp1, t emp2;cor r ect = Check( t emp1, t emp2) ;
}
i f ( ! pDC- >I sPr i nt i ng( ) ){
/ / col ori f ( pVi ew- >m_sel ect i on. Fi nd( t hi s) ){
{pDC- >MoveTo( cent r . x- l enght 1, cent r . y) ;pDC- >Li neTo( cent r . x+l enght 1, cent r . y) ;
pDC- >MoveTo( cent r . x, cent r . y- m_di m/ 2) ;pDC- >Li neTo( cent r . x, cent r . y) ;
f or ( i nt i = 0; i < m_nLower Li nk; i ++){
pDC- >MoveTo( cent r . x- l enght 1 + ( m_di m* m_space* i ) , cent r . y+m_di m/ 2) ;pDC- >Li neTo( cent r . x- l enght 1 + ( m_di m* m_space* i ) , cent r . y) ;i f ( m_Lower [ i ] ! = NULL)
Dr awCi r cl e( CPoi nt ( cent r . x - l enght 1 + ( m_di m* m_space* i ) , cent r . y+m_di m/ 2) ,m_di m/ 12, pDC) ;
}}br eak;
case PARALLEL:{
pDC- >MoveTo( cent r . x- l enght 1, cent r . y- space_bt w_l i nes) ;pDC- >Li neTo( cent r . x+l enght 1, cent r . y- space_bt w_l i nes) ;
pDC- >MoveTo( cent r . x- l enght 1, cent r . y+space_bt w_l i nes) ;pDC- >Li neTo( cent r . x+l enght 1, cent r . y+space_bt w_l i nes) ;
pDC- >MoveTo( cent r . x, cent r . y- m_di m/ 2) ;pDC- >Li neTo( cent r . x, cent r . y- space_bt w_l i nes) ;
f or ( i nt i = 0; i < m_nLower Li nk; i ++){
pDC- >MoveTo( cent r . x - l enght 1 + ( m_di m* m_space* i ) , cent r . y+m_di m/ 2) ;pDC- >Li neTo( cent r . x - l enght 1 + ( m_di m* m_space* i ) , cent r . y+space_bt w_l i nes) ;
i f ( m_Lower [ i ] ! = NULL)Dr awCi r cl e( CPoi nt ( cent r . x - l enght 1 + ( m_di m* m_space* i ) , cent r . y+m_di m/ 2) ,
m_di m/ 12, pDC) ;}
}
176
br eak;case CONVERGENCE:
{pDC- >MoveTo( cent r . x- l enght 2, cent r . y) ;pDC- >Li neTo( cent r . x+l enght 2, cent r . y) ;
pDC- >MoveTo( cent r . x, cent r . y+m_di m/ 2) ;pDC- >Li neTo( cent r . x, cent r . y) ;
f or ( i nt i = 0; i < m_nUpper Li nk; i ++){
pDC- >MoveTo( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y- m_di m/ 2) ;pDC- >Li neTo( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y) ;i f ( m_Upper [ i ] ! = NULL)
Dr awCi r cl e( CPoi nt ( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y- m_di m/ 2) ,m_di m/ 12, pDC) ;
}}br eak;
case SYNCRO:{
pDC- >MoveTo( cent r . x- l enght 2, cent r . y- space_bt w_l i nes) ;pDC- >Li neTo( cent r . x+l enght 2, cent r . y- space_bt w_l i nes) ;
pDC- >MoveTo( cent r . x- l enght 2, cent r . y+space_bt w_l i nes) ;pDC- >Li neTo( cent r . x+l enght 2, cent r . y+space_bt w_l i nes) ;
pDC- >MoveTo( cent r . x, cent r . y+m_di m/ 2) ;pDC- >Li neTo( cent r . x, cent r . y+space_bt w_l i nes) ;
f or ( i nt i = 0; i < m_nUpper Li nk; i ++){
pDC- >MoveTo( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y- m_di m/ 2) ;pDC- >Li neTo( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y- space_bt w_l i nes) ;
i f ( m_Upper [ i ] ! = NULL)Dr awCi r cl e( CPoi nt ( cent r . x - l enght 2 + ( m_di m* m_space* i ) , cent r . y- m_di m/ 2) ,
m_di m/ 12, pDC) ;}
}br eak;
}
i f ( changed)pDC- >Sel ect Obj ect ( pOr i gi nal Pen) ;
}
CPoi nt CMul t i Obj : : Get Handl e( i nt count , CDr awObj * * pAr c){
ASSERT_VALI D ( t hi s) ;
i f ( count < 10)r et ur n m_posi t i on;
i f ( ( count >= 20) && ( count < 30) ){
i nt n = count - 20;i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
i f ( m_nUpper Li nk- 1 < n)r et ur n NULL;
el se{
177
* pAr c = m_Upper [ n] ;r et ur n CPoi nt ( m_posi t i on. x - ( m_nUpper Li nk- 1) * m_space + m_space* n* 2,
m_posi t i on. y- 1) ;}
}el se
i f ( n ! = 0)r et ur n NULL;
el se{
* pAr c = m_Upper [ 0] ;r et ur n CPoi nt ( m_posi t i on. x, m_posi t i on. y- 1) ;
}
}
i f ( ( count >= 30) && ( count < 40) ){
i nt n = count - 30;i f ( m_Type == SELECT | | m_Type == PARALLEL){
i f ( m_nLower Li nk- 1 < n)r et ur n NULL;
el se{
* pAr c = m_Lower [ n] ;r et ur n CPoi nt ( m_posi t i on. x - ( m_nLower Li nk- 1) * m_space + m_space* n* 2,
m_posi t i on. y+1) ;}
}el se
i f ( n ! = 0)r et ur n NULL;
el se{
* pAr c = m_Lower [ 0] ;r et ur n CPoi nt ( m_posi t i on. x, m_posi t i on. y+1) ;
}}
r et ur n NULL;}
i nt CMul t i Obj : : Hi t Test ( CPoi nt poi nt ){
CDr awObj * t emp;
i f ( m_Type == SELECT | | m_Type == PARALLEL){
i f ( Get Handl e( 20, &t emp) == poi nt )r et ur n 20;
f or ( i nt i = 0; i < m_nLower Li nk; i ++)i f ( Get Handl e( 30+i , &t emp) == poi nt )
r et ur n ( 30+i ) ;}
i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
i f ( Get Handl e( 30, &t emp) == poi nt )r et ur n 30;
f or ( i nt i = 0; i < m_nUpper Li nk; i ++)i f ( Get Handl e( 20+i , &t emp) == poi nt )
r et ur n ( 20+i ) ;
178
}
i f ( m_r ect . Pt I nRect ( CPoi nt ( poi nt . x* m_gr i d, poi nt . y* m_gr i d) ) )r et ur n 1;
r et ur n 0;}
voi d CMul t i Obj : : Sel ect I t em( CSFCVi ew * pVi ew){
i nt down;
i f ( pVi ew- >m_sel ect i on. Fi nd( t hi s) )r et ur n;
pVi ew- >m_sel ect i on. AddTai l ( t hi s) ;
i nt nLi nk;i f ( ( m_Type == SELECT) | | ( m_Type == PARALLEL) ){
down = 1;nLi nk = m_nLower Li nk;
}el se{
down = 0;nLi nk = m_nUpper Li nk;
}
f or ( i nt i = 0; i < nLi nk; i ++){
i f ( m_Lower [ 0+i * down] ! = NULL){
CAr cObj * pAr c = ( CAr cObj * ) ( m_Lower [ 0+i * down] ) ;
i f ( ! pVi ew- >m_sel ect i on. Fi nd( pAr c) )pVi ew- >m_sel ect i on. AddTai l ( pAr c) ;
i f ( pAr c- >m_Upper [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ 0] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ 0] ) ) ;
i f ( pAr c- >m_Lower [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) ;
pVi ew- >I nval Ar c( pAr c, pAr c- >m_nPoi nt s- 1) ;}i f ( m_Upper [ 0+i * ( 1- down) ] ! = NULL){
CAr cObj * pAr c = ( CAr cObj * ) m_Upper [ 0+i * ( 1- down) ] ;i f ( ! pVi ew- >m_sel ect i on. Fi nd( pAr c) )
pVi ew- >m_sel ect i on. AddTai l ( pAr c) ;
i f ( pAr c- >m_Upper [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ 0] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ 0] ) ) ;
i f ( pAr c- >m_Lower [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) ;
179
pVi ew- >I nval Ar c( pAr c, pAr c- >m_nPoi nt s- 1) ;
}}
}
voi d CMul t i Obj : : OnEdi t Pr oper t y( CSFCVi ew * pVi ew){
CMul t i Dl g dl g;i nt ol d_nLi nks;i nt ol d_space = m_space;BOOL val i d = TRUE;i nt i ;
CDr awObj * t emp;
dl g. m_spaci ng = m_space/ 2;
i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
dl g. m_number _of _l i nks = m_nUpper Li nk;ol d_nLi nks = m_nUpper Li nk;f or ( i =0; i <MAX_PARALLEL; i ++)
val i d = val i d && ( m_Upper [ i ] == NULL) ;}
i f ( m_Type == SELECT | | m_Type == PARALLEL){
dl g. m_number _of _l i nks = m_nLower Li nk;ol d_nLi nks = m_nLower Li nk;f or ( i =0; i <MAX_PARALLEL; i ++)
val i d = val i d && ( m_Lower [ i ] == NULL) ;}
i f ( val i d)dl g. di mmed = FALSE;
el sedl g. di mmed = TRUE;
i f ( dl g. DoModal ( ) == I DOK){
m_space = dl g. m_spaci ng* 2;
i f ( val i d){
i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO)m_nUpper Li nk = dl g. m_number _of _l i nks;
i f ( m_Type == SELECT | | m_Type == PARALLEL)m_nLower Li nk = dl g. m_number _of _l i nks;
}
pVi ew- >I nval Obj ( t hi s) ;CPoi nt cent er = m_r ect . Cent er Poi nt ( ) ;m_r ect . l ef t = cent er . x- m_di m* m_space* ( dl g. m_number _of _l i nks- 1) / 2;m_r ect . r i ght = cent er . x+m_di m* m_space* ( dl g. m_number _of _l i nks- 1) / 2;
i f ( ( ol d_nLi nks ! = dl g. m_number _of _l i nks) | | ( ol d_space ! = m_space) ){
CAr cObj * pAr c;i f ( m_Type == CONVERGENCE | | m_Type == SYNCRO){
f or ( i = 0; i < m_nUpper Li nk; i ++){
pAr c = ( CAr cObj * ) m_Upper [ i ] ;
180
i f ( pAr c ! = NULL){
pVi ew- >I nval Ar c( pAr c, - 1) ;i f ( pAr c- >m_Upper [ 0] == t hi s)
pAr c- >m_poi nt s[ 0] = Get Handl e( 20+i , &t emp) ;el se
pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s- 1] = Get Handl e( 20+i , &t emp) ;pVi ew- >I nval Ar c( pAr c, - 1) ;
}}
}i f ( m_Type == SELECT | | m_Type == PARALLEL){
f or ( i = 0; i < m_nLower Li nk; i ++){
pAr c = ( CAr cObj * ) m_Lower [ i ] ;i f ( pAr c ! = NULL){
pVi ew- >I nval Ar c( pAr c, - 1) ;i f ( pAr c- >m_Upper [ 0] == t hi s)
pAr c- >m_poi nt s[ 0] = Get Handl e( 30+i , &t emp) ;el se
pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s- 1] = Get Handl e( 30+i , &t emp) ;pVi ew- >I nval Ar c( pAr c, - 1) ;
}}
}}
}}
voi d CMul t i Obj : : Ser i al i ze( CAr chi ve & ar ){
CDr awObj : : Ser i al i ze( ar ) ;
i f ( ar . I sSt or i ng( ) )ar << m_space;
el sear >> m_space;
}
BOOL CMul t i Obj : : Check( i nt & war , i nt & er r ){
CDr awObj * pLi nk;BOOL val i d;BOOL cor r ect = TRUE;war = 0;er r = 0;CAr cObj * pAr c;i nt i ;
f or ( i =0; i <m_nUpper Li nk; i ++){
i f ( m_Upper [ i ] ! = NULL){
pLi nk = m_Upper [ i ] ;ASSERT ( pLi nk- >m_Type == Ar Obj ) ;pAr c = ( CAr cObj * ) pLi nk;i f ( pAr c- >m_Upper [ 0] == t hi s){
cor r ect = FALSE; / / non par t e ni ent e da sopr a!er r | = ER_UPFLOWERROR;
}el se
181
{ASSERT ( pAr c- >m_Lower [ 0] == t hi s) ;i f ( ( m_Type == PARALLEL) | | ( m_Type == CONVERGENCE) ){
val i d = ( pAr c- >m_Upper [ 0] - >m_Type == Tr Obj ) ;}i f ( ( m_Type == SELECT) | | ( m_Type == SYNCRO) ){
val i d = ( pAr c- >m_Upper [ 0] - >m_Type == PhObj ) ;}
cor r ect &= val i d; / / val i di t \ UNI CODE{ 0xe0} del l i nki f ( ! val i d)
er r | = ER_UPFLOWERROR;}
}el se{
cor r ect = FALSE;er r | = ER_I NCOMPLI NK; / / f l oat i ng l i nk;
}}f or ( i =0; i <m_nLower Li nk; i ++){
i f ( m_Lower [ i ] ! = NULL){
pLi nk = m_Lower [ i ] ;ASSERT ( pLi nk- >m_Type == Ar Obj ) ;pAr c = ( CAr cObj * ) pLi nk;i f ( pAr c- >m_Lower [ 0] == t hi s){
cor r ect = FALSE; / / non ar r i va ni ent e da sot t o!er r | = ER_UPFLOWERROR;
}el se{
ASSERT ( pAr c- >m_Upper [ 0] == t hi s) ;i f ( ( m_Type == PARALLEL) | | ( m_Type == CONVERGENCE) ){
val i d = ( pAr c- >m_Lower [ 0] - >m_Type == PhObj ) ;}i f ( ( m_Type == SELECT) | | ( m_Type == SYNCRO) ){
val i d = ( pAr c- >m_Lower [ 0] - >m_Type == Tr Obj ) ;}
cor r ect &= val i d; / / val i di t \ UNI CODE{ 0xe0} del l i nki f ( ! val i d)
er r | = ER_DWFLOWERROR;}
}el se{
cor r ect = FALSE;er r | = ER_I NCOMPLI NK; / / f l oat i ng l i nk;
}}
r et ur n cor r ect ;
}
182
classCMultiDlg
File : MultiDlg.h#i f ! def i ned( AFX_MULTI DLG_H__936AE540_070A_11D3_8FB1_D5274BB07574__I NCLUDED_)#def i ne AFX_MULTI DLG_H__936AE540_070A_11D3_8FB1_D5274BB07574__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / Mul t i Dl g. h : header f i l e/ /
cl ass CMul t i Dl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
v i r t ual BOOL OnI ni t Di al og( ) ;BOOL di mmed;CMul t i Dl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CMul t i Dl g)enum { I DD = I DD_MULTI _DLG } ;i nt m_number _of _l i nks;i nt m_spaci ng;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CMul t i Dl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr i vat e:
pr ot ect ed:CEdi t & number Of Li nks( ) { r et ur n * ( CEdi t * ) Get Dl gI t em ( I DC_N_LI NKS) ; }CEdi t & space( ) { r et ur n * ( CEdi t * ) Get Dl gI t em ( I DC_SPACI NG) ; }
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CMul t i Dl g)
/ / NOTE: t he Cl assWi zar d wi l l add member f unct i ons her e/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_MULTI DLG_H__936AE540_070A_11D3_8FB1_D5274BB07574__I NCLUDED_)
File : MultiDlg.cpp
183
/ / Mul t i Dl g. cpp : i mpl ement at i on f i l e/ /
#i ncl ude ’ ’ st daf x. h’ ’#i ncl ude ’ ’ SFC. h’ ’#i ncl ude ’ ’ Mul t i Dl g. h’ ’
#i f def _DEBUG#def i ne new DEBUG_NEW#undef THI S_FI LEst at i c char THI S_FI LE[ ] = __FI LE__;#endi f
i f ( di mmed)number Of Li nks( ) . Enabl eWi ndow( FALSE) ;
el senumber Of Li nks( ) . Enabl eWi ndow( TRUE) ;
r et ur n TRUE;}
184
classCMultiTool
File : MultiTool.h/ / Mul t i Tool . h: i nt er f ace f or t he CMul t i Tool cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
#i f ! def i ned( AFX_MULTI TOOL_H__D6DE3CE3_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_)#def i ne AFX_MULTI TOOL_H__D6DE3CE3_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Mul t i 1Obj . h’ ’
c l ass CMul t i Tool{publ i c:
st at i c voi d OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags, const CPoi nt & poi nt ) ;st at i c voi d OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;st at i c voi d OnLBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;st at i c voi d OnNewObj ( CSFCVi ew * pVi ew, CPoi nt poi nt , Obj Type t ype) ;CMul t i Tool ( ) ;v i r t ual ~CMul t i Tool ( ) ;
} ;
#endi f / / ! def i ned( AFX_MULTI TOOL_H__D6DE3CE3_F649_11D2_8FB1_FEFE0258614A__I NCLUDED_)
File : MultiTool.cpp/ / Mul t i Tool . cpp: i mpl ement at i on of t he CMul t i Tool cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
{CAr cObj * pAr c;pAr c = CAr cTool : : OnNewAr c( pObj , pLi nk, i , n_l i nk) ;pVi ew- >I nval Ar c( pAr c, - 1) ;
}}
}
swi t ch ( m_Obj Tool ){case mul t i 1:
OnNewObj ( pVi ew, poi nt , SELECT) ;br eak;
case mul t i 2:OnNewObj ( pVi ew, poi nt , PARALLEL) ;
186
br eak;case mul t i 3:
OnNewObj ( pVi ew, poi nt , CONVERGENCE) ;br eak;
case mul t i 4:OnNewObj ( pVi ew, poi nt , SYNCRO) ;br eak;
}}
voi d CMul t i Tool : : OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
CDr awObj * pObj ;i f ( pVi ew- >m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CRect r ect Save;pObj = pObj Li st - >Get Tai l ( ) ;r ect Save = pObj - >m_r ect ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
m_Obj Tool = sel ect i on;r ect Save. I nf l at eRect ( m_gr i d, m_gr i d) ;pVi ew- >DocToCl i ent ( r ect Save) ;pVi ew- >I nval i dat eRect ( r ect Save, TRUE) ;pVi ew- >m_pl aci ng = FALSE;pVi ew- >m_pt Li nk. RemoveAl l ( ) ;
}}
}
voi d CMul t i Tool : : OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags,const CPoi nt & poi nt )
{CPoi nt l ocal = poi nt ;CDr awObj * pObj ;CCl i ent DC dc( pVi ew) ;CPoi nt cr oss;
CDr awObj * t emp;
i f ( pVi ew- >m_pl aci ng){
CDr awObj * pLi nk;pObj = pObj Li st - >Get Tai l ( ) ;pVi ew- >Cl i ent ToDoc( l ocal ) ;
CPoi nt near Poi nt = pVi ew- >Near est OnGr i d( l ocal ) ;CPoi nt cent er = pObj - >m_posi t i on;i f ( cent er ! = near Poi nt ){
pVi ew- >I nval Obj ( pObj ) ;pObj - >MoveTo( near Poi nt ) ;pVi ew- >I nval Obj ( pObj ) ;
i nt n_l i nk;
pVi ew- >m_pt Li nk. RemoveAl l ( ) ;
f or ( i nt i =0; i <( pObj - >m_nUpper Li nk) ; i ++){
pLi nk = pObj - >Eval uat eUpper Li nk( pVi ew, &n_l i nk, i ) ;
187
i f ( pLi nk)i f ( ( ( pLi nk- >m_Type == PhObj ) && ( ( pObj - >m_Type == SELECT) | | ( pObj ->m_Type == SYNCRO) ) ) | |
{pVi ew- >m_pt Li nk. AddTai l ( pObj - >Get Handl e( 30+i , &t emp) ) ;MessageBeep( 0) ;
}}
}}
}
classCPageSplitDlg
File : PageSplitDlg.h#i f ! def i ned( AFX_PAGESPLI TDLG_H__A224B022_69CA_11D3_8FB1_E40F10A5AF6D__I NCLUDED_)#def i ne AFX_PAGESPLI TDLG_H__A224B022_69CA_11D3_8FB1_E40F10A5AF6D__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / PageSpl i t Dl g. h : header f i l e/ /
cl ass CPageSpl i t Dl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
/ / member f unct i onsCPageSpl i t Dl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct orCSi ze Number Of Pages( ) ;voi d Updat eSt r i ng( ) ;i nt Scal e2Sl i de( doubl e scal e) ;doubl e Sl i de2Scal e( i nt sl i de) ;
/ / member var i abl esdoubl e m_scal e;i nt m_numPage;CSi ze m_pageSi ze;CSi ze m_si zeDoc;
188
/ / Di al og Dat a/ / { { AFX_DATA( CPageSpl i t Dl g)enum { I DD = I DD_PAGE_SPLI T } ;CSt r i ng m_docsi zeSt r ;CSt r i ng m_pagesi zeSt r ;CSt r i ng m_scal eSt r ;CSt r i ng m_numPageSt r ;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CPageSpl i t Dl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CPageSpl i t Dl g)af x_msg voi d OnPai nt ( ) ;vi r t ual BOOL OnI ni t Di al og( ) ;af x_msg voi d OnVScr ol l ( UI NT nSBCode, UI NT nPos, CScr ol l Bar * pScr ol l Bar ) ;af x_msg voi d OnPr i nt er Set up( ) ;/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_PAGESPLI TDLG_H__A224B022_69CA_11D3_8FB1_E40F10A5AF6D__I NCLUDED_)
File : PageSplit.cpp/ / PageSpl i t Dl g. cpp : i mpl ement at i on f i l e/ /
CPageSpl i t Dl g: : CPageSpl i t Dl g( CWnd* pPar ent / * =NULL* / ): CDi al og( CPageSpl i t Dl g: : I DD, pPar ent )
{
189
/ / { { AFX_DATA_I NI T( CPageSpl i t Dl g)m_docsi zeSt r = _T( ’ ’ ’ ’ ) ;m_pagesi zeSt r = _T( ’ ’ ’ ’ ) ;m_scal eSt r = _T( ’ ’ ’ ’ ) ;m_numPageSt r = _T( ’ ’ ’ ’ ) ;/ / } } AFX_DATA_I NI T
}
voi d CPageSpl i t Dl g: : DoDat aExchange( CDat aExchange* pDX){
CDi al og: : DoDat aExchange( pDX) ;/ / { { AFX_DATA_MAP( CPageSpl i t Dl g)DDX_Text ( pDX, I DC_DOCSI ZE, m_docsi zeSt r ) ;DDX_Text ( pDX, I DC_PAGESI ZE, m_pagesi zeSt r ) ;DDX_Text ( pDX, I DC_SCALE, m_scal eSt r ) ;DDX_Text ( pDX, I DC_NUM_PAGES, m_numPageSt r ) ;DDV_MaxChar s( pDX, m_numPageSt r , 2) ;/ / } } AFX_DATA_MAP
}
BEGI N_MESSAGE_MAP( CPageSpl i t Dl g, CDi al og)/ / { { AFX_MSG_MAP( CPageSpl i t Dl g)ON_WM_PAI NT( )ON_WM_VSCROLL( )ON_BN_CLI CKED( I D_PRI NTER_SETUP, OnPr i nt er Set up)/ / } } AFX_MSG_MAP
CPai nt DC dc( t hi s) ; / / devi ce cont ext f or pai nt i ng/ / TODO: Add your message handl er code her eCRect r ect 1( 20, 50, 140, 150) ;MapDi al ogRect ( r ect 1) ;
doubl e sx, sy, scal e;CSi ze n = Number Of Pages( ) ;
CRect PagRect ( 80, 100, 80, 100) ;CRect DocRect ;PagRect . I nf l at eRect ( ( i nt ) ( scal e* ( doubl e) ( m_pageSi ze. cx* n. cx) / 2. 0) ,
( i nt ) ( scal e* ( doubl e) ( m_pageSi ze. cy* n. cy) / 2. 0) ) ;
DocRect . l ef t = PagRect . l ef t ;DocRect . t op = PagRect . t op;DocRect . r i ght = PagRect . l ef t ;DocRect . bot t om = PagRect . t op;DocRect . I nf l at eRect ( 0, 0,
( i nt ) ( ( doubl e) m_si zeDoc. cx* scal e* m_scal e) ,( i nt ) ( ( doubl e) m_si zeDoc. cy* scal e* m_scal e) ) ;
190
dc. Sel ect St ockObj ect ( WHI TE_BRUSH) ;MapDi al ogRect ( PagRect ) ;dc. Rect angl e( PagRect ) ;
dc. Sel ect St ockObj ect ( LTGRAY_BRUSH) ;MapDi al ogRect ( DocRect ) ;dc. Rect angl e( DocRect ) ;
dc. Sel ect St ockObj ect ( BLACK_PEN) ;i nt del t a = PagRect . Wi dt h( ) / n. cx;f or ( i nt i =1; i <n. cx; i ++){
dc. MoveTo( PagRect . l ef t +i * del t a, PagRect . t op) ;dc. Li neTo( PagRect . l ef t +i * del t a, PagRect . bot t om) ;
}del t a = PagRect . Hei ght ( ) / n. cy;f or ( i =1; i <n. cy; i ++){
dc. MoveTo( PagRect . l ef t , PagRect . t op+i * del t a) ;dc. Li neTo( PagRect . r i ght , PagRect . t op+i * del t a) ;
}}
BOOL CPageSpl i t Dl g: : OnI ni t Di al og( ){
CDi al og: : OnI ni t Di al og( ) ;
CSl i der Ct r l * pSl i de = ( CSl i der Ct r l * ) Get Dl gI t em( I DC_SCALE_SLI DER) ;pSl i de- >Set Range( 1, 14) ;pSl i de- >Set Li neSi ze( 10) ;pSl i de- >Set Ti cFr eq( 1) ;pSl i de- >Set Pos( Scal e2Sl i de( m_scal e) ) ;
CSi ze n = Number Of Pages( ) ;m_numPage = n. cx* n. cy;
Updat eSt r i ng( ) ;
r et ur n TRUE; / / r et ur n TRUE unl ess you set t he f ocus t o a cont r ol/ / EXCEPTI ON: OCX Pr oper t y Pages shoul d r et ur n FALSE
}
doubl e CPageSpl i t Dl g: : Sl i de2Scal e( i nt sl i de){
doubl e t emp;
i f ( s l i de == 10)t emp = 1. 0;
el se i f ( s l i de < 10)t emp = ( ( doubl e) sl i de/ 10. 0) ;
el set emp = ( ( ( doubl e) sl i de- 8. 0) / 2. 0) ;
r et ur n t emp;}
i nt CPageSpl i t Dl g: : Scal e2Sl i de( doubl e scal e){
i nt t emp;
i f ( scal e == 1. 0)t emp = 10;
el se i f ( scal e <1)
191
t emp = ( i nt ) ( scal e* 10. 0) ;el se
t emp = ( i nt ) ( scal e* 2. 0) +8;
r et ur n t emp;}
voi d CPageSpl i t Dl g: : Updat eSt r i ng( ){
m_pagesi zeSt r . For mat ( ’ ’ %i x%i ’ ’ , m_pageSi ze. cx, m_pageSi ze. cy) ;m_docsi zeSt r . For mat ( ’ ’ %i x%i ’ ’ , m_si zeDoc. cx, m_si zeDoc. cy) ;m_scal eSt r . For mat ( ’ ’ x %. 1f ’ ’ , m_scal e) ;m_numPageSt r . For mat ( ’ ’ %i ’ ’ , m_numPage) ;
Updat eDat a( FALSE) ;}
CSi ze CPageSpl i t Dl g: : Number Of Pages( ){
i nt nx, ny;
nx = ( i nt ) cei l ( ( doubl e) m_si zeDoc. cx* m_scal e/ ( doubl e) m_pageSi ze. cx) ;ny = ( i nt ) cei l ( ( doubl e) m_si zeDoc. cy* m_scal e/ ( doubl e) m_pageSi ze. cy) ;m_numPage = nx* ny;
r et ur n CSi ze( nx, ny) ;}
voi d CPageSpl i t Dl g: : OnVScr ol l ( UI NT nSBCode, UI NT nPos, CScr ol l Bar * pScr ol l Bar ){
/ / TODO: Add your message handl er code her e and/ or cal l def aul tCSl i der Ct r l * pSl i de = ( CSl i der Ct r l * ) Get Dl gI t em( I DC_SCALE_SLI DER) ;
m_scal e = Sl i de2Scal e( pSl i de- >Get Pos( ) ) ;CRect r ect ( 15, 40, 145, 155) ;MapDi al ogRect ( r ect ) ;I nval i dat eRect ( r ect ) ;Updat eWi ndow( ) ;Updat eSt r i ng( ) ;
CDi al og: : OnVScr ol l ( nSBCode, nPos, pScr ol l Bar ) ;}
voi d CPageSpl i t Dl g: : OnPr i nt er Set up( ){
/ / TODO: Add your cont r ol not i f i cat i on handl er code her et heApp. OnFi l ePr i nt Set up( ) ;
CPr i nt I nf o* pPr i nt I nf o = new CPr i nt I nf o;pPr i nt I nf o- >m_bDi r ect = TRUE;
CSFCVi ew * pVi ew = ( CSFCVi ew * ) Get Par ent ( ) ;pVi ew- >DoPr epar ePr i nt i ng( pPr i nt I nf o) ;
i f ( pPr i nt I nf o- >m_pPD- >m_pd. hDC == NULL)ASSERT( FALSE) ; / / common mi st ake get s t r apped her e
el se{
CDC dcPr i nt ;dcPr i nt . At t ach( pPr i nt I nf o- >m_pPD- >m_pd. hDC) ;
m_pageSi ze. cx = dcPr i nt . Get Devi ceCaps( HORZSI ZE) ;m_pageSi ze. cy = dcPr i nt . Get Devi ceCaps( VERTSI ZE) ;
192
}del et e pPr i nt I nf o;
CRect r ect ( 15, 40, 145, 155) ;MapDi al ogRect ( r ect ) ;I nval i dat eRect ( r ect ) ;Updat eWi ndow( ) ;Updat eSt r i ng( ) ;
#i f ! def i ned( AFX_PHASEOBJ_H__AE826182_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_)#def i ne AFX_PHASEOBJ_H__AE826182_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Dr awObj . h’ ’#i ncl ude ’ ’ SFC. h’ ’#i ncl ude ’ ’ Ti me. h’ ’/ *c l ass CSFCDoc;cl ass CSFCVi ew;cl ass CDr awAr c;* /
c l ass CPhaseObj : publ i c CDr awObj{publ i c:/ / pr ot ect ed:
CPhaseObj ( ) { } ;DECLARE_SERI AL ( CPhaseObj )
publ i c:v i r t ual BOOL Check( i nt &war , i nt & er r ) ;v i r t ual CPoi nt Get Handl e( i nt count , CDr awObj * * pAr c) ;v i r t ual CSt r i ng Text ual For m( ) ;v i r t ual i nt maxCount ( ) ;v i r t ual voi d Expand( bool det ai l ed) ;v i r t ual voi d Ser i al i ze( CAr chi ve& ar ) ;v i r t ual voi d OnEdi t Pr oper t y( CSFCVi ew * pVi ew) ;vi r t ual voi d Sel ect I t em( CSFCVi ew* pVi ew) ;vi r t ual voi d Dr awI t em( CSFCVi ew* pVi ew, CDC * pDC) ;vi r t ual voi d Dr awDet ai l s( CSFCVi ew * pVi ew, CDC * pDC) ;BOOL m_i ni t i al ;CSt r i ng m_name;i nt m_number ;CSt r i ng m_qual i f i er ;CTi mer m_t i me;CPhaseObj ( CPoi nt poi nt , BOOL i ni t i al ) ;
CPhaseObj : : CPhaseObj ( CPoi nt poi nt , BOOL i ni t i al ): CDr awObj ( PhObj ){
m_r ect . l ef t = poi nt . x* m_gr i d- m_di m;m_r ect . t op = poi nt . y* m_gr i d- m_di m;i f ( det ai l edVi ew)
m_r ect . r i ght = poi nt . x* m_gr i d+4* m_di m;el se
m_r ect . r i ght = poi nt . x* m_gr i d+m_di m;m_r ect . bot t om = poi nt . y* m_gr i d+m_di m;
m_posi t i on = poi nt ;m_i ni t i al = i ni t i al ;
m_nLower Li nk = 1;m_nUpper Li nk = 1;
m_name = ’ ’ No Act i on’ ’ ;m_qual i f i er = ’ ’ N’ ’ ;
m_t i me. d = 0;m_t i me. h = 0;m_t i me. m = 0;m_t i me. s = 0;m_t i me. ms = 0;
194
}
CPhaseObj : : ~CPhaseObj ( ){}
voi d CPhaseObj : : Dr awDet ai l s( CSFCVi ew * pVi ew, CDC * pDC){
CRect r ect = m_r ect ;CPoi nt cent r = CPoi nt ( m_posi t i on. x* m_gr i d, m_posi t i on. y* m_gr i d) ;i nt bor der = m_di m/ 3;
CRect qual Rect ( cent r . x+m_di m, cent r . y- bor der ,cent r . x+m_di m+2* bor der +1, cent r . y+bor der +1) ;
CRect nameRect ( cent r . x+m_di m+2* bor der , cent r . y- bor der ,cent r . x+4* m_di m+1, cent r . y+bor der +1) ;
pDC- >Rect angl e( qual Rect ) ;pDC- >Rect angl e( nameRect ) ;pDC- >MoveTo( cent r . x+m_di m- bor der , cent r . y) ;pDC- >Li neTo( cent r . x+m_di m, cent r . y) ;
pDC- >Dr awText ( m_qual i f i er , qual Rect , DT_CENTER | DT_SI NGLELI NE | DT_VCENTER) ;pDC- >Dr awText ( m_name, nameRect , DT_SI NGLELI NE | DT_VCENTER) ;pDC- >Sel ect Obj ect ( pOl dFont ) ;
}
voi d CPhaseObj : : Dr awI t em( CSFCVi ew * pVi ew, CDC * pDC){
CRect r ect = CRect ( m_posi t i on. x* m_gr i d- m_di m, m_posi t i on. y* m_gr i d- m_di m,m_posi t i on. x* m_gr i d+m_di m, m_posi t i on. y* m_gr i d+m_di m) ;
CPoi nt cent r ( m_posi t i on. x* m_gr i d, m_posi t i on. y* m_gr i d) ;
CPen MyPen;CPen * pOr i gi nal Pen;BOOL changed = FALSE;BOOL cor r ect ;
i nt bor der = m_di m/ 3;
i f ( pVi ew- >bCheck){
i nt t emp1, t emp2;cor r ect = Check( t emp1, t emp2) ;
}}r ect . Def l at eRect ( bor der , bor der ) ;pDC- >Rect angl e( &r ect ) ;
pDC- >MoveTo( cent r . x, cent r . y- m_di m) ;pDC- >Li neTo( cent r . x, cent r . y- m_di m+bor der ) ;pDC- >MoveTo( cent r . x, cent r . y+m_di m) ;pDC- >Li neTo( cent r . x, cent r . y+m_di m- bor der ) ;
r ect . Def l at eRect ( bor der * 2/ 3, bor der * 2/ 3) ;i f ( m_i ni t i al )
pDC- >Rect angl e( &r ect ) ;
CSt r i ng num;num. For mat ( ’ ’ %i ’ ’ , m_number +100* n_SFC) ;
pDC- >Dr awText ( num, r ect , DT_CENTER | DT_SI NGLELI NE | DT_VCENTER) ;
pDC- >Sel ect Obj ect ( pOl dFont ) ;
i f ( m_Upper [ 0] ! = NULL)Dr awCi r cl e( CPoi nt ( cent r . x, cent r . y- m_di m) , m_di m/ 12, pDC) ;
i f ( m_Lower [ 0] ! = NULL)Dr awCi r cl e( CPoi nt ( cent r . x, cent r . y+m_di m) , m_di m/ 12, pDC) ;
i f ( changed)pDC- >Sel ect Obj ect ( pOr i gi nal Pen) ;
}
voi d CPhaseObj : : Sel ect I t em( CSFCVi ew * pVi ew){
i f ( pVi ew- >m_sel ect i on. Fi nd( t hi s) )r et ur n;
pVi ew- >m_sel ect i on. AddTai l ( t hi s) ;
i f ( m_Lower [ 0] ! = NULL){
CAr cObj * pAr c = ( CAr cObj * ) ( m_Lower [ 0] ) ;
i f ( ! pVi ew- >m_sel ect i on. Fi nd( pAr c) )pVi ew- >m_sel ect i on. AddTai l ( pAr c) ;
i f ( pAr c- >m_Upper [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ 0] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ 0] ) ) ;
i f ( pAr c- >m_Lower [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) ;
pVi ew- >I nval Ar c( pAr c, pAr c- >m_nPoi nt s- 1) ;}
196
i f ( m_Upper [ 0] ! = NULL){
CAr cObj * pAr c = ( CAr cObj * ) m_Upper [ 0] ;i f ( ! pVi ew- >m_sel ect i on. Fi nd( pAr c) )
pVi ew- >m_sel ect i on. AddTai l ( pAr c) ;
i f ( pAr c- >m_Upper [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ 0] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ 0] ) ) ;
i f ( pAr c- >m_Lower [ 0] == t hi s)i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) )
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ pAr c- >m_nPoi nt s - 1] ) ) ;
pVi ew- >I nval Ar c( pAr c, pAr c- >m_nPoi nt s- 1) ;
}
}
voi d CPhaseObj : : OnEdi t Pr oper t y( CSFCVi ew * pVi ew){
CAct i onDl g dl g;
dl g. m_name = m_name;dl g. m_number = m_number ;dl g. m_i ni t i al = m_i ni t i al ;dl g. m_qual i f i er = m_qual i f i er ;dl g. m_t i meSt r = m_t i me. Ti meSt r i ng( ) ;dl g. m_t i me. d = m_t i me. d;dl g. m_t i me. h = m_t i me. h;dl g. m_t i me. m = m_t i me. m;dl g. m_t i me. s = m_t i me. s;dl g. m_t i me. ms = m_t i me. ms;
i f ( dl g. DoModal ( ) == I DOK){
/ / r et r i eve t he di al og dat am_name = dl g. m_name;m_number = dl g. m_number ;m_i ni t i al = dl g. m_i ni t i al ;m_qual i f i er = dl g. m_qual i f i er ;m_t i me. d = dl g. m_t i me. d;m_t i me. h = dl g. m_t i me. h;m_t i me. m = dl g. m_t i me. m;m_t i me. s = dl g. m_t i me. s;m_t i me. ms = dl g. m_t i me. ms;dl g. m_t i meSt r = m_t i me. Ti meSt r i ng( ) ;
}
}
voi d CPhaseObj : : Ser i al i ze( CAr chi ve & ar ){
CDr awObj : : Ser i al i ze( ar ) ;
i f ( ar . I sSt or i ng( ) ){
ar << m_i ni t i al ;ar << m_name;ar << m_number ;ar << m_qual i f i er ;m_t i me. Ser i al i ze( ar ) ;
}
197
el se{
ar >> m_i ni t i al ;ar >> m_name;ar >> m_number ;ar >> m_qual i f i er ;m_t i me. Ser i al i ze( ar ) ;
}
}
voi d CPhaseObj : : Expand( bool det ai l ed){
i f ( det ai l ed)m_r ect . r i ght += 3* m_di m;
el sem_r ect . r i ght - = 3* m_di m;
}
i nt CPhaseObj : : maxCount ( ){
i nt max = 0;POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * pObj ;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type == PhObj ){
CPhaseObj * pPhasObj = ( CPhaseObj * ) pObj ;i f ( max < pPhasObj - >m_number )
max = pPhasObj - >m_number ;}
}max++;r et ur n max;
}
CSt r i ng CPhaseObj : : Text ual For m( ){
CSt r i ng t xt ;CSt r i ng s1, s2, t ;
t =m_qual i f i er ;
i f ( m_i ni t i al )s1 = ’ ’ I NI TI AL_STEP’ ’ ;
el ses1 = ’ ’ STEP’ ’ ;
i f ( t == ’ ’ D’ ’ | | t == ’ ’ L’ ’ | | t == ’ ’ DS’ ’ | | t == ’ ’ SL’ ’ | | t == ’ ’ SD’ ’ | | t == ’ ’ PW’ ’ )s2. For mat ( ’ ’ %s, %s’ ’ , m_qual i f i er , m_t i me. Ti meSt r i ng( ) ) ;
el ses2 = t ;
t xt . For mat ( ’ ’ %s S%i : %s( %s) : END_STEP; \ n’ ’ , s1, m_number +100* n_SFC,m_name, s2) ;
r et ur n t xt ;}
CPoi nt CPhaseObj : : Get Handl e( i nt count , CDr awObj * * pAr c){
ASSERT_VALI D ( t hi s) ;
198
swi t ch ( count ) {case 1:
r et ur n m_posi t i on;br eak;
case 20:{
* pAr c = m_Upper [ 0] ;r et ur n ( m_posi t i on- CPoi nt ( 0, 2) ) ;
}br eak;
case 30:{
* pAr c = m_Lower [ 0] ;r et ur n ( m_posi t i on+CPoi nt ( 0, 2) ) ;
}br eak;
}r et ur n NULL;
}
BOOL CPhaseObj : : Check( i nt & war , i nt & er r ){
CDr awObj * pLi nk;BOOL dwnFl ow, val i d;BOOL cor r ect = TRUE;war = 0;er r = 0;CAr cObj * pAr c;
i f ( m_Upper [ 0] ! = NULL){
pLi nk = m_Upper [ 0] ;ASSERT ( pLi nk- >m_Type == Ar Obj ) ;pAr c = ( CAr cObj * ) pLi nk;i f ( pAr c- >m_Upper [ 0] == t hi s){
dwnFl ow = FALSE;val i d = ( pAr c- >m_Lower [ 0] - >m_Type == Tr Obj | |
#i f ! def i ned( AFX_PHASETOOL_H__C6C2E0C4_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_)#def i ne AFX_PHASETOOL_H__C6C2E0C4_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
200
#i ncl ude ’ ’ PhaseObj . h’ ’
c l ass CPhaseTool{publ i c:
/ / member f unct i onsst at i c voi d OnRBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;st at i c voi d OnNewObj ( CSFCVi ew * pVi ew, CPoi nt poi nt , BOOL i ni t i al ) ;st at i c voi d OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags, const CPoi nt & poi nt ) ;CPhaseTool ( ) ;vi r t ual ~CPhaseTool ( ) ;st at i c voi d OnLBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;
} ;
#endi f / / ! def i ned( AFX_PHASETOOL_H__C6C2E0C4_EC1E_11D2_8FB1_D5D277192105__I NCLUDED_)
#i f ! def i ned( AFX_SELECTTOOL_H__2CDBBBA1_ED20_11D2_8FB1_EAB479398702__I NCLUDED_)#def i ne AFX_SELECTTOOL_H__2CDBBBA1_ED20_11D2_8FB1_EAB479398702__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Dr awObj . h’ ’
c l ass CSel ect Tool{publ i c:
/ / member f unct i onsst at i c voi d OnLBut t onDbl Cl k( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;CSel ect Tool ( ) ;
203
vi r t ual ~CSel ect Tool ( ) ;st at i c voi d OnMouseMove( CSFCVi ew* pVi ew, UI NT nFl ags, const CPoi nt & poi nt ) ;st at i c voi d OnLBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;
/ / member var i abl esst at i c CPoi nt c_down;st at i c CPoi nt c_l ast ;st at i c voi d OnLBut t onUp( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;
} ;
#endi f / / ! def i ned( AFX_SELECTTOOL_H__2CDBBBA1_ED20_11D2_8FB1_EAB479398702__I NCLUDED_)
pVi ew- >m_sel ect i on. RemoveAl l ( ) ;pVi ew- >m_pt Sel ect i on. RemoveAl l ( ) ;
sel ect Mode = net Sel ect ;CCl i ent DC dc( pVi ew) ;CRect r ect ( l ocal . x, l ocal . y, l ocal . x, l ocal . y) ;r ect . Nor mal i zeRect ( ) ;dc. Dr awFocusRect ( r ect ) ;r et ur n;
}pVi ew- >Get Document ( ) - >Updat eAl l Vi ews( NULL, HI NT_UPDATE_LI ST, NULL) ;
}
voi d CSel ect Tool : : OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags, const CPoi nt & poi nt ){
CSFCDoc* pDoc = pVi ew- >Get Document ( ) ;CPoi nt l ocal = poi nt ;pVi ew- >Cl i ent ToDoc( l ocal ) ;
i f ( sel ect Mode == net Sel ect ){
CCl i ent DC dc( pVi ew) ;
205
CRect r ect ( c_down. x, c_down. y, c_l ast . x, c_l ast . y) ;pVi ew- >DocToCl i ent ( r ect ) ;dc. Dr awFocusRect ( r ect ) ;
r ect . Set Rect ( c_down. x, c_down. y, l ocal . x, l ocal . y) ;pVi ew- >DocToCl i ent ( r ect ) ;dc. Dr awFocusRect ( r ect ) ;
c_l ast = l ocal ;
r et ur n;}
i f ( sel ect Mode == move){
CPoi nt del t a = ( CPoi nt ) ( pVi ew- >Near est OnGr i d( l ocal ) - pVi ew->Near est OnGr i d( c_down) ) ;
CAr cObj * pAr c;CDr awObj * pObj ;i f ( CPoi nt ( del t a - ol d_del t a) ! = CPoi nt ( 0, 0) ){
POSI TI ON pos = pVi ew- >m_sel ect i on. Get HeadPosi t i on( ) ;i f ( pos ! = NULL){
pObj = pVi ew- >m_sel ect i on. Get Next ( pos) ;CPoi nt ol dPosi t i on = pObj - >m_posi t i on;pVi ew- >I nval Obj ( pObj ) ;pObj - >MoveTo( ol dPosi t i on + del t a - ol d_del t a) ;pVi ew- >I nval Obj ( pObj ) ;
}whi l e ( pos ! = NULL){
pObj = pVi ew- >m_sel ect i on. Get Next ( pos) ;CPoi nt ol dPosi t i on = pObj - >m_posi t i on;i f ( pObj - >m_Type ! = Ar Obj ){
pVi ew- >I nval Obj ( pObj ) ;pObj - >MoveTo( ol dPosi t i on + del t a - ol d_del t a) ;pVi ew- >I nval Obj ( pObj ) ;
}el se{
pAr c = ( CAr cObj * ) pObj ;pAr c- >MovePt To( pVi ew, del t a - ol d_del t a) ;
}}ol d_del t a = del t a;
}}
}
voi d CSel ect Tool : : OnLBut t onUp( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
i f ( sel ect Mode == net Sel ect ){
CCl i ent DC dc( pVi ew) ;CRect r ect ( c_down. x, c_down. y, c_l ast . x, c_l ast . y) ;r ect . Nor mal i zeRect ( ) ;
CRect r ect T;POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * pObj ;
whi l e ( pos ! = NULL)
206
{pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type ! = Ar Obj ){
i f ( r ect T. I nt er sect Rect ( r ect , pObj - >m_r ect ) )pObj - >Sel ect I t em( pVi ew) ;
}el se{
/ / l ’ ogget t o \ UNI CODE{ 0xe8} un ar co per cui qual i al t r i punt i sono st at i sel ?CAr cObj * pAr c;pAr c = ( CAr cObj * ) pObj ;f or ( i nt i =0; i <pAr c- >m_nPoi nt s; i ++){
CPoi nt pt ( pAr c- >m_poi nt s[ i ] . x* m_gr i d, pAr c- >m_poi nt s[ i ] . y* m_gr i d) ;i f ( r ect . Pt I nRect ( pt ) )
i f ( ! pVi ew- >m_pt Sel ect i on. Fi nd( &( pAr c- >m_poi nt s[ i ] ) ) ){
pVi ew- >m_pt Sel ect i on. AddTai l ( &( pAr c- >m_poi nt s[ i ] ) ) ;i f ( ! pVi ew- >m_sel ect i on. Fi nd( pAr c) )
pVi ew- >m_sel ect i on. AddTai l ( pAr c) ;}
}}
}pVi ew- >DocToCl i ent ( c_down) ;pVi ew- >DocToCl i ent ( c_l ast ) ;r ect . Set Rect ( c_down. x, c_down. y, c_l ast . x, c_l ast . y) ;r ect . Nor mal i zeRect ( ) ;dc. Dr awFocusRect ( r ect ) ;
sel ect Mode = none;}
pVi ew- >Get Document ( ) - >Updat eAl l Vi ews( NULL, HI NT_UPDATE_LI ST, NULL) ;sel ect Mode = none;
}
voi d CSel ect Tool : : OnLBut t onDbl Cl k( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
CDr awObj * pObj ;POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;BOOL Sel = FALSE;
CPoi nt l ocal = poi nt ;pVi ew- >Cl i ent ToDoc( l ocal ) ;l ocal = pVi ew- >Near est OnGr i d( l ocal ) ;
whi l e ( pos ! = NULL && ! Sel ){
pObj = pObj Li st - >Get Next ( pos) ;
i f ( ( pObj - >Hi t Test ( l ocal ) ) && ( pObj - >m_Type ! = Ar Obj ) ){
Sel = TRUE;/ / MessageBeep( 0) ;
pObj - >OnEdi t Pr oper t y( pVi ew) ;pVi ew- >I nval Obj ( pObj ) ;
}}
}
207
classCSFCApp
File : SFC.h/ / SFC. h : mai n header f i l e f or t he SFC appl i cat i on/ /
#i f ! def i ned( AFX_SFC_H__39DB6104_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)#def i ne AFX_SFC_H__39DB6104_E601_11D2_B1B8_EDD329A68936__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i f ndef __AFXWI N_H__#er r or i ncl ude ’ st daf x. h’ bef or e i ncl udi ng t hi s f i l e f or PCH
#endi f
#i ncl ude ’ ’ r esour ce. h’ ’ / / mai n symbol s
#i ncl ude <af xt empl . h> / / SFC uses col l ect i on cl ass t empl at es
#i ncl ude ’ ’ Dr awObj . h’ ’#i ncl ude ’ ’ PhaseObj . h’ ’/ / #i ncl ude ’ ’ Dr awAr c. h’ ’
t ypedef CTypedPt r Li st <CObLi st , CDr awObj * > CDr awObj Li st ;t ypedef CMapWor dToPt r CDr awGl obObj Map;
/ / t ypedef CTypedPt r Li st <CObLi st , CDr awAr c * > CDr awAr cLi st ;
t ypedef CLi st <CPoi nt * , CPoi nt * > CDr awPoi nt Li st Ref ;t ypedef CLi st <CPoi nt , CPoi nt > CDr awPoi nt Li st ;
enum Obj Tool{
phase0,phase,t r ansi t i on,ar c,sel ect i on,mul t i 1,mul t i 2,mul t i 3,mul t i 4,
} ;
/ / ext er n CDr awGl obObj Li st Gl obObj Li st ;ext er n CDr awObj Li st * pObj Li st ;ext er n CDr awGl obObj Map Gl obObj Li st Map;ext er n CSt r i ng names[ 10] ;/ / ext er n CDr awAr cLi st Ar cLi st ;ext er n i nt m_gr i d, m_scal i ng, m_nSFC, Act i veSFC;ext er n i nt m_di m;ext er n bool det ai l edVi ew;ext er n Obj Tool m_Obj Tool ;
/ / ext er n Sel ect Mode sel ect Mode;/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / CSFCApp:/ / See SFC. cpp f or t he i mpl ement at i on of t hi s cl ass/ /
208
cl ass CSFCApp : publ i c CWi nApp{publ i c:
CSFCApp( ) ;
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CSFCApp)publ i c:vi r t ual BOOL I ni t I nst ance( ) ;/ / } } AFX_VI RTUAL
/ / I mpl ement at i on
/ / { { AFX_MSG( CSFCApp)af x_msg voi d OnAppAbout ( ) ;af x_msg voi d OnFi l ePr i nt Set up( ) ;/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_SFC_H__39DB6104_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)
File : SFC.cpp/ / SFC. cpp : Def i nes t he cl ass behavi or s f or t he appl i cat i on./ /
#i f def _DEBUG#def i ne new DEBUG_NEW#undef THI S_FI LEst at i c char THI S_FI LE[ ] = __FI LE__;#endi f
/ / gl obal var i abl esi nt m_di m = 108;bool det ai l edVi ew = FALSE;i nt m_gr i d = m_di m/ 2;i nt m_scal i ng = 1;i nt m_nSFC = 1;i nt Act i veSFC = 1;
CDr awObj Li st * pObj Li st ;CDr awGl obObj Map Gl obObj Li st Map;CSt r i ng names[ 10] ;Obj Tool m_Obj Tool ;
BEGI N_MESSAGE_MAP( CSFCApp, CWi nApp)/ / { { AFX_MSG_MAP( CSFCApp)ON_COMMAND( I D_APP_ABOUT, OnAppAbout )ON_COMMAND( I D_FI LE_PRI NT_SETUP, OnFi l ePr i nt Set up)/ / } } AFX_MSG_MAP/ / St andar d f i l e based document commandsON_COMMAND( I D_FI LE_NEW, CWi nApp: : OnFi l eNew)ON_COMMAND( I D_FI LE_OPEN, CWi nApp: : OnFi l eOpen)/ / St andar d pr i nt set up commandON_COMMAND( I D_FI LE_PRI NT_SETUP, CWi nApp: : OnFi l ePr i nt Set up)
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // / CSFCApp i ni t i al i zat i on
BOOL CSFCApp: : I ni t I nst ance( ){/ / Af xEnabl eCont r ol Cont ai ner ( ) ;
/ / St andar d i ni t i al i zat i on/ / I f you ar e not usi ng t hese f eat ur es and wi sh t o r educe t he si ze/ / of your f i nal execut abl e, you shoul d r emove f r om t he f ol l owi ng/ / t he speci f i c i ni t i al i zat i on r out i nes you do not need.
#i f def _AFXDLLEnabl e3dCont r ol s( ) ; / / Cal l t hi s when usi ng MFC i n a shar ed DLL
#el seEnabl e3dCont r ol sSt at i c( ) ; / / Cal l t hi s when l i nki ng t o MFC st at i cal l y
#endi f
/ / Change t he r egi st r y key under whi ch our set t i ngs ar e st or ed./ / You shoul d modi f y t hi s st r i ng t o be somet hi ng appr opr i at e/ / such as t he name of your company or or gani zat i on.Set Regi st r yKey( _T( ’ ’ Local AppWi zar d- Gener at ed Appl i cat i ons’ ’ ) ) ;
LoadSt dPr of i l eSet t i ngs( ) ; / / Load st andar d I NI f i l e opt i ons ( i ncl udi ng MRU)
/ / Regi st er t he appl i cat i on’ s document t empl at es. Document t empl at es/ / ser ve as t he connect i on bet ween document s, f r ame wi ndows and vi ews.
CSi ngl eDocTempl at e* pDocTempl at e;pDocTempl at e = new CSi ngl eDocTempl at e(
I DR_MAI NFRAME,RUNTI ME_CLASS( CSFCDoc) ,RUNTI ME_CLASS( CMai nFr ame) , / / mai n SDI f r ame wi ndowRUNTI ME_CLASS( CSFCVi ew) ) ;
AddDocTempl at e( pDocTempl at e) ;
/ / Par se command l i ne f or st andar d shel l commands, DDE, f i l e open
210
CCommandLi neI nf o cmdI nf o;Par seCommandLi ne( cmdI nf o) ;
/ / Di spat ch commands speci f i ed on t he command l i nei f ( ! Pr ocessShel l Command( cmdI nf o) )
r et ur n FALSE;
/ / The one and onl y wi ndow has been i ni t i al i zed, so show and updat e i t .m_pMai nWnd- >ShowWi ndow( SW_SHOW) ;m_pMai nWnd- >Updat eWi ndow( ) ;
/ / Di al og Dat a/ / { { AFX_DATA( CAbout Dl g)enum { I DD = I DD_ABOUTBOX } ;/ / } } AFX_DATA
/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CAbout Dl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / { { AFX_MSG( CAbout Dl g)/ / No message handl er s
/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
CAbout Dl g: : CAbout Dl g( ) : CDi al og( CAbout Dl g: : I DD){
/ / { { AFX_DATA_I NI T( CAbout Dl g)/ / } } AFX_DATA_I NI T
}
voi d CAbout Dl g: : DoDat aExchange( CDat aExchange* pDX){
/ / TODO: Add your command handl er code her eCPr i nt Di al og PD( TRUE) ;DoPr i nt Di al og( &PD) ;
/ / pDev = ( DEVMODE* ) PD. m_pd. hDevMode;}
classCSFCDlg
File : SFCDlg.h#i f ! def i ned( AFX_SFCDLG_H__5562D882_6122_11D3_8FB1_C1A2D11E696F__I NCLUDED_)#def i ne AFX_SFCDLG_H__5562D882_6122_11D3_8FB1_C1A2D11E696F__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / SFCDl g. h : header f i l e/ /
cl ass CSFCDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CSFCDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CSFCDl g)enum { I DD = I DD_EDI T_SFC_NAME } ;CSt r i ng m_SFCname;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CSFCDl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CSFCDl g)
/ / NOTE: t he Cl assWi zar d wi l l add member f unct i ons her e/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
212
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_SFCDLG_H__5562D882_6122_11D3_8FB1_C1A2D11E696F__I NCLUDED_)
File : SFCDlg.cpp/ / SFCDl g. cpp : i mpl ement at i on f i l e/ /
#i f ! def i ned( AFX_SFCDOC_H__39DB610A_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)#def i ne AFX_SFCDOC_H__39DB610A_E601_11D2_B1B8_EDD329A68936__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#def i ne STEP 1#def i ne I NI TI AL_STEP 2#def i ne END_STEP 3#def i ne TRANSI TI ON 4#def i ne ASSI GNMENT 5#def i ne SFC 6#def i ne END_SFC 7#def i ne BEGI N_PROJECT 8#def i ne END_PROJECT 9#def i ne FROM 10#def i ne TO 11#def i ne END 12
cl ass CSFCDoc : publ i c CDocument{pr ot ect ed: / / cr eat e f r om ser i al i zat i on onl y
CSFCDoc( ) ;DECLARE_DYNCREATE( CSFCDoc)CSi ze m_si zeDoc[ 10] ;
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CSFCDoc)publ i c:vi r t ual BOOL OnNewDocument ( ) ;
/ / vi r t ual voi d Ser i al i ze( CAr chi ve& ar ) ;/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpubl i c:
CSi ze Get DocSi ze( ) { r et ur n m_si zeDoc[ Act i veSFC] ; }CSt r i ng Er r or St r ( i nt er r ) ;CSt r i ng War ni ngSt r ( i nt war ) ;BOOL CheckSFC( voi d) ;voi d I ni t i al i ze( ) ;voi d Del et eAl l SFC( ) ;st at i c voi d Del et eLi st ( CDr awObj Li st * pLi st ) ;st at i c voi d Remove( CDr awObj * pObj ) ;vi r t ual ~CSFCDoc( ) ;
#i f def _DEBUGvi r t ual voi d Asser t Val i d( ) const ;vi r t ual voi d Dump( CDumpCont ext & dc) const ;
#endi f
/ / member var i abl espr i vat e:
BOOL I mpor t MLF( LPCSTR l pszFi l eName) ;BOOL SavePr oj ( LPCSTR l pszFi l eName) ;CSt r i ng m_st r Fi l eName;CSt r i ng m_st r Fi l ePat hName;CSt r i ng m_st r MFLName;CSt r i ng m_st r MFLPat hName;CSt r i ng m_st r Pr j Name;CSt r i ng m_st r Pr j Pat hName;
214
BOOL SaveFi l e ( LPCSTR l pszFi l eName) ;BOOL Cr eat eMLF( LPCSTR l pszFi l eName) ;
/ / Gener at ed message map f unct i onspr ot ect ed:
/ / { { AFX_MSG( CSFCDoc)af x_msg voi d OnFi l eSave( ) ;af x_msg voi d OnFi l eSaveAs( ) ;af x_msg voi d OnFi l eOpen( ) ;af x_msg voi d OnPr oj Open( ) ;af x_msg voi d OnPr oj Save( ) ;af x_msg voi d OnSavePr oj As( ) ;af x_msg voi d OnRemoveSFC( ) ;af x_msg voi d OnAddSFC( ) ;af x_msg voi d OnFi l eNew( ) ;af x_msg voi d OnMLFCr eat e( ) ;af x_msg voi d OnSet DocSi ze( ) ;af x_msg voi d OnCheckBut t on( ) ;af x_msg voi d OnI mpor t But t on( ) ;/ / } } AFX_MSG
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_SFCDOC_H__39DB610A_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)
File : SFCDoc.cpp/ / SFCDoc. cpp : i mpl ement at i on of t he CSFCDoc cl ass/ /
ON_COMMAND( I D_FI LE_SAVE, OnFi l eSave)ON_COMMAND( I D_FI LE_SAVE_AS, OnFi l eSaveAs)ON_COMMAND( I D_FI LE_OPEN, OnFi l eOpen)ON_COMMAND( I D_PROJ_OPEN, OnPr oj Open)ON_COMMAND( I D_PROJ_SAVE, OnPr oj Save)ON_COMMAND( I D_SAVE_PROJ_AS, OnSavePr oj As)ON_COMMAND( I DM_REMOVESFC, OnRemoveSFC)ON_COMMAND( I DM_SFC_ADDSFC, OnAddSFC)ON_COMMAND( I D_FI LE_NEW, OnFi l eNew)ON_COMMAND( I D_MLF_CREATE, OnMLFCr eat e)ON_COMMAND( I D_SETDOCSI ZE_BUTTON, OnSet DocSi ze)ON_COMMAND( I D_CHECK_BUTTON, OnCheckBut t on)ON_COMMAND( I D_EXPORT_BUTTON, OnI mpor t But t on)/ / } } AFX_MSG_MAP
pFr ame- >RemoveAl l SFC( ) ;Gl obObj Li st Map. RemoveAl l ( ) ;
}
voi d CSFCDoc: : OnFi l eSave( ){
OnFi l eSaveAs ( ) ;}
voi d CSFCDoc: : OnFi l eSaveAs( ){
char szFi l t er s[ ] = ’ ’ SFC f i l es ( * . sf c) | * . sf c| Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
CFi l eDi al og dl g ( FALSE, ’ ’ sf c ’ ’ , m_st r Fi l ePat hName, OFN_OVERWRI TEPROMPT |OFN_PATHMUSTEXI ST | OFN_HI DEREADONLY, szFi l t er s, NULL) ;
i f ( dl g. DoModal ( ) == I DOK)
217
{i f ( SaveFi l e ( dl g. Get Pat hName ( ) ) ){
m_st r Fi l eName = dl g. Get Fi l eTi t l e ( ) ;m_st r Fi l ePat hName = dl g. Get Pat hName ( ) ;
}}
}
BOOL CSFCDoc: : SaveFi l e( LPCSTR l pszFi l eName){
/ / TODO: Add your command handl er code her eCFi l e f i l e;BOOL bResul t = TRUE;i nt count , i ;CDr awObj * pObj ;
i f ( f i l e. Open ( l pszFi l eName, CFi l e: : modeCr eat e | CFi l e: : modeWr i t e) ){
CWai t Cur sor wai t ;CAr chi ve ar ( &f i l e, CAr chi ve: : st or e) ;
/ / assol ut i zzazi one degl i ogget t i .POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;count = 1;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;pObj - >m_absol ut e = count ;count ++;
}
ar << names[ Act i veSFC] ;ar << m_si zeDoc[ Act i veSFC] ;
pObj Li st - >Ser i al i ze( ar ) ;
/ / r egi st r a i l i nk per ogni ogget t opos = pObj Li st - >Get HeadPosi t i on( ) ;count = pObj Li st - >Get Count ( ) ;
/ / r egi st r a i l numer o di ogget t iar << count ;
whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;
/ / i ndi r i zzo assol ut o del l ’ ogget t oar << pObj - >m_absol ut e;
f or ( i =0; i <pObj - >m_nUpper Li nk; i ++)i f ( pObj - >m_Upper [ i ] ! = NULL)
ar << pObj - >m_Upper [ i ] - >m_absol ut e;el se
ar << ( i nt ) 0;
f or ( i =0; i <pObj - >m_nLower Li nk; i ++)i f ( pObj - >m_Lower [ i ] ! = NULL)
ar << pObj - >m_Lower [ i ] - >m_absol ut e;el se
ar << ( i nt ) 0;
}
218
}el se{
CSt r i ng st r i ng;st r i ng. For mat ( ’ ’ Unabl e t o cr eat e %s’ ’ , l pszFi l eName) ;MessageBox ( NULL, st r i ng, ’ ’ Er r or ’ ’ , MB_I CONEXCLAMATI ON | MB_OK) ;bResul t = FALSE;
}r et ur n bResul t ;
}
voi d CSFCDoc: : OnFi l eOpen( ){
/ / TODO: Add your command handl er code her echar szFi l t er s[ ] = ’ ’ SFC f i l es ( * . sf c) | * . sf c| Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
CFi l eDi al og dl g ( TRUE, ’ ’ sf c ’ ’ , ’ ’ * . sf c ’ ’ , OFN_FI LEMUSTEXI ST |OFN_HI DEREADONLY, szFi l t er s, NULL) ;
i f ( dl g. DoModal ( ) == I DOK){
CFi l e f i l e;i nt count , i ;CDr awObj * pObj ;
f i l ename = dl g. Get Pat hName( ) ;i f ( f i l e. Open ( f i l ename, CFi l e: : modeRead) ){
CWai t Cur sor wai t ;CAr chi ve ar ( &f i l e, CAr chi ve: : l oad) ;
/ / MessageBeep( 0) ;CSFCDoc: : Del et eLi st ( pObj Li st ) ;
ar >> names[ Act i veSFC] ;ar >> m_si zeDoc[ Act i veSFC] ;
CMai nFr ame* pFr ame = ( CMai nFr ame * ) Af xGet App( ) - >m_pMai nWnd;CDi al ogBar * pTabDl g = &pFr ame- >m_wndTabBar ;CTabCt r l * pTab = ( CTabCt r l * ) pTabDl g- >Get Dl gI t em( I DC_TAB) ;
i f ( pTab ! = NULL){
i nt i t em = pTab- >Get Cur Sel ( ) ;
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_TEXT;
CSt r i ng TabTxt = ’ ’ SFC ’ ’ ;CSt r i ng num;num. For mat ( ’ ’ %i - ’ ’ , Act i veSFC) ;TabTxt += num;TabTxt += names[ Act i veSFC] ;TabCt r l I t em. pszText = TabTxt . Get Buf f er ( 10) ; / / ’ ’ SFC 1’ ’ ;pTab- >Set I t em( i t em, &TabCt r l I t em ) ;
}
pObj Li st - >Ser i al i ze( ar ) ;
/ / r i cost r ui sce i l i nk per ogni ogget t o
/ / numer o di ogget t iar >> count ;
219
i nt absol ut e;i nt l i nkTo;CDr awObj * pLi nk;whi l e ( count > 0){
ar >> absol ut e;count - - ;
/ / t r ova i l punt at or e a quest o ogget t o:POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;BOOL f i nd = FALSE;i =0;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
i ++;pObj = pObj Li st - >Get Next ( pos) ;f i nd = ( pObj - >m_absol ut e == absol ut e) ;
}
f or ( i =0; i <pObj - >m_nUpper Li nk; i ++){
ar >> l i nkTo;
i f ( l i nkTo ! = 0){
pos = pObj Li st - >Get HeadPosi t i on( ) ;f i nd = FALSE;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
pLi nk = pObj Li st - >Get Next ( pos) ;f i nd = ( pLi nk- >m_absol ut e == l i nkTo) ;
}
ASSERT( f i nd) ;
/ / aggi or na i l col l egament opObj - >m_Upper [ i ] = pLi nk;
}el se
pObj - >m_Upper [ i ] = NULL;}
f or ( i =0; i <pObj - >m_nLower Li nk; i ++){
ar >> l i nkTo;
i f ( l i nkTo ! = 0){
pos = pObj Li st - >Get HeadPosi t i on( ) ;f i nd = FALSE;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
pLi nk = pObj Li st - >Get Next ( pos) ;f i nd = ( pLi nk- >m_absol ut e == l i nkTo) ;
}
ASSERT( f i nd) ;
/ / aggi or na i l col l egament opObj - >m_Lower [ i ] = pLi nk;
}el se
pObj - >m_Lower [ i ] = NULL;
220
}m_st r Fi l eName = dl g. Get Fi l eTi t l e ( ) ;m_st r Fi l ePat hName = dl g. Get Pat hName ( ) ;
}
}}Updat eAl l Vi ews( NULL) ;
}
voi d CSFCDoc: : OnPr oj Save( ){
/ / TODO: Add your command handl er code her e
i f ( ! m_st r Pr j Name. I sEmpt y ( ) )SavePr oj ( m_st r Pr j Pat hName) ;
el seOnSavePr oj As( ) ;
}
voi d CSFCDoc: : OnSavePr oj As( ){
/ / TODO: Add your command handl er code her echar szFi l t er s[ ] = ’ ’ Pr j f i l es ( * . pr j ) | * . pr j | Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
CFi l eDi al og dl g ( FALSE, ’ ’ pr j ’ ’ , m_st r Pr j Pat hName, OFN_OVERWRI TEPROMPT |OFN_PATHMUSTEXI ST | OFN_HI DEREADONLY, szFi l t er s, NULL) ;
i f ( dl g. DoModal ( ) == I DOK){
i f ( SavePr oj ( dl g. Get Pat hName ( ) ) ){
m_st r Pr j Name = dl g. Get Fi l eTi t l e ( ) ;m_st r Pr j Pat hName = dl g. Get Pat hName ( ) ;
CMai nFr ame* pFr ame = ( CMai nFr ame * ) Af xGet App( ) - >m_pMai nWnd;pFr ame- >Updat eWi ndowTi t l e( m_st r Pr j Name) ;
}}
}
BOOL CSFCDoc: : SavePr oj ( LPCSTR l pszFi l eName){
CFi l e f i l e;BOOL bResul t = TRUE;i nt count , i ;CDr awObj * pObj ;
i f ( f i l e. Open ( l pszFi l eName, CFi l e: : modeCr eat e | CFi l e: : modeWr i t e) ){
CWai t Cur sor wai t ;CAr chi ve ar ( &f i l e, CAr chi ve: : st or e) ;
/ / PROJECT SAVE : GENERAL I NFORMATI ON/ /
221
i nt t ot = Gl obObj Li st Map. Get Count ( ) ;ar << t ot ; / / t ot al n of SFC
/ / f l ow t r ought al l t he l i st sCDr awObj Li st * pPi vot Li st ;voi d * pTemp;WORD nSFC;
POSI TI ON pos1 = Gl obObj Li st Map. Get St ar t Posi t i on( ) ;whi l e ( pos1 ! = NULL){
Gl obObj Li st Map. Get Next Assoc( pos1, nSFC, pTemp) ;pPi vot Li st = ( CDr awObj Li st * ) pTemp;
ar << nSFC;ar << names[ nSFC] ;ar << m_si zeDoc[ nSFC] ; / / document si ze
/ / assol ut i zzazi one degl i ogget t i .POSI TI ON pos = pPi vot Li st - >Get HeadPosi t i on( ) ;count = 1;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;pObj - >m_absol ut e = count ;count ++;
}pPi vot Li st - >Ser i al i ze( ar ) ;
/ / r egi st r a i l i nk per ogni ogget t opos = pPi vot Li st - >Get HeadPosi t i on( ) ;count = pPi vot Li st - >Get Count ( ) ;
/ / r egi st r a i l numer o di ogget t iar << count ;
whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;
/ / i ndi r i zzo assol ut o del l ’ ogget t oar << pObj - >m_absol ut e;
f or ( i =0; i <pObj - >m_nUpper Li nk; i ++)i f ( pObj - >m_Upper [ i ] ! = NULL)
ar << pObj - >m_Upper [ i ] - >m_absol ut e;el se
ar << ( i nt ) 0;
f or ( i =0; i <pObj - >m_nLower Li nk; i ++)i f ( pObj - >m_Lower [ i ] ! = NULL)
ar << pObj - >m_Lower [ i ] - >m_absol ut e;el se
ar << ( i nt ) 0;
}}
}el se{
CSt r i ng st r i ng;st r i ng. For mat ( ’ ’ Unabl e t o cr eat e %s’ ’ , l pszFi l eName) ;MessageBox ( NULL, st r i ng, ’ ’ Er r or ’ ’ , MB_I CONEXCLAMATI ON | MB_OK) ;bResul t = FALSE;
}
222
r et ur n bResul t ;
}
voi d CSFCDoc: : OnPr oj Open( ){
/ / TODO: Add your command handl er code her e
char szFi l t er s[ ] = ’ ’ SFC f i l es ( * . pr j ) | * . pr j | Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
CFi l eDi al og dl g ( TRUE, ’ ’ pr j ’ ’ , ’ ’ * . pr j ’ ’ , OFN_FI LEMUSTEXI ST |OFN_HI DEREADONLY, szFi l t er s, NULL) ;
i f ( dl g. DoModal ( ) == I DOK){
CFi l e f i l e;i nt count , i ;CDr awObj * pObj ;
f i l ename = dl g. Get Pat hName( ) ;i f ( f i l e. Open ( f i l ename, CFi l e: : modeRead) ){
CWai t Cur sor wai t ;CAr chi ve ar ( &f i l e, CAr chi ve: : l oad) ;
whi l e ( t ot > 0) / / scor r e t ut t e l e l i st e{
ar >> nSFC;ar >> names[ nSFC] ;ar >> m_si zeDoc[ nSFC] ; / / document si zeCDr awObj Li st * pNewLi st = new CDr awObj Li st ;Gl obObj Li st Map[ nSFC] = pNewLi st ;pFr ame- >AddSFC( nSFC) ;pNewLi st - >Ser i al i ze( ar ) ;pObj Li st = pNewLi st ;
/ / r i cost r ui sce i l i nk per ogni ogget t o/ / numer o di ogget t iar >> count ;
i nt absol ut e;i nt l i nkTo;CDr awObj * pLi nk;
whi l e ( count > 0){
ar >> absol ut e;count - - ;
/ / t r ova i l punt at or e a quest o ogget t o:POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;BOOL f i nd = FALSE;
223
i =0;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
i ++;pObj = pObj Li st - >Get Next ( pos) ;f i nd = ( pObj - >m_absol ut e == absol ut e) ;
}
f or ( i =0; i <pObj - >m_nUpper Li nk; i ++){
ar >> l i nkTo;
i f ( l i nkTo ! = 0){
pos = pObj Li st - >Get HeadPosi t i on( ) ;f i nd = FALSE;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
pLi nk = pObj Li st - >Get Next ( pos) ;f i nd = ( pLi nk- >m_absol ut e == l i nkTo) ;
}
ASSERT( f i nd) ;
/ / aggi or na i l col l egament opObj - >m_Upper [ i ] = pLi nk;
}el se
pObj - >m_Upper [ i ] = NULL;}
f or ( i =0; i <pObj - >m_nLower Li nk; i ++){
ar >> l i nkTo;
i f ( l i nkTo ! = 0){
pos = pObj Li st - >Get HeadPosi t i on( ) ;f i nd = FALSE;whi l e ( ( pos ! = NULL) && ( ! f i nd) ){
pLi nk = pObj Li st - >Get Next ( pos) ;f i nd = ( pLi nk- >m_absol ut e == l i nkTo) ;
}
ASSERT( f i nd) ;
/ / aggi or na i l col l egament opObj - >m_Lower [ i ] = pLi nk;
}el se
pObj - >m_Lower [ i ] = NULL;
}}t ot - - ;m_st r Pr j Name = dl g. Get Fi l eTi t l e ( ) ;m_st r Pr j Pat hName = dl g. Get Pat hName ( ) ;
CMai nFr ame* pFr ame = ( CMai nFr ame * ) Af xGet App( ) - >m_pMai nWnd;pFr ame- >Updat eWi ndowTi t l e( m_st r Pr j Name) ;
}}
}
224
Updat eAl l Vi ews( NULL) ;
}
voi d CSFCDoc: : OnRemoveSFC( ){
/ / TODO: Add your command handl er code her eCMai nFr ame* pFr ame = ( CMai nFr ame * ) Af xGet App( ) - >m_pMai nWnd;
i f ( pFr ame- >MessageBox( ’ ’ Ar e you Sur e ?’ ’ , ’ ’ Del et e’ ’ , MB_OKCANCEL |MB_I CONEXCLAMATI ON | MB_DEFBUTTON2) == I DOK)
{CDi al ogBar * pTabDl g = &pFr ame- >m_wndTabBar ;CTabCt r l * pTab = ( CTabCt r l * ) pTabDl g- >Get Dl gI t em( I DC_TAB) ;
i f ( pTab ! = NULL){
i nt i t em = pTab- >Get Cur Sel ( ) ;i nt nSFC; / / numer o del l ’ SFC da cancel l ar e
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_PARAM;pTab- >Get I t em( i t em, &TabCt r l I t em) ;nSFC = TabCt r l I t em. l Par am;
CDr awObj Li st * pLi st = ( CDr awObj Li st * ) Gl obObj Li st Map[ nSFC] ;Del et eLi st ( pLi st ) ;
Gl obObj Li st Map. RemoveKey( nSFC) ;
i f ( Gl obObj Li st Map. Get Count ( ) > 0){
pFr ame- >RemoveSFC( nSFC) ;m_nSFC- - ;
}el se
I ni t i al i ze( ) ;
}}
}
voi d CSFCDoc: : OnAddSFC( ){
/ / TODO: Add your command handl er code her eCMai nFr ame* pFr ame = ( CMai nFr ame * ) Af xGet App( ) - >m_pMai nWnd;CDi al ogBar * pTabDl g = &pFr ame- >m_wndTabBar ;CTabCt r l * pTab = ( CTabCt r l * ) pTabDl g- >Get Dl gI t em( I DC_TAB) ;
i f ( pTab ! = NULL){
m_nSFC++;i nt count = pTab- >Get I t emCount ( ) ;
TC_I TEM TabCt r l I t em;TabCt r l I t em. mask = TCI F_PARAM;
/ / f i nd f i r st f r ee posi t i on f r om 1 t o 9i nt max = 0;BOOL f r ee = FALSE;whi l e ( ! f r ee){
max++;
225
f r ee = TRUE;f or ( i nt j =0; j <count ; j ++){
pTab- >Get I t em( j , &TabCt r l I t em) ;i f ( max == TabCt r l I t em. l Par am)
f r ee = FALSE;}
}
CDr awObj Li st * pNewLi st = new CDr awObj Li st ;Gl obObj Li st Map[ max] = pNewLi st ;names[ max] = ’ ’ NoName’ ’ ;pObj Li st = pNewLi st ;
pFr ame- >AddSFC( max) ; / / cont i ene l ’ aggi or nament o sf c at t ual e}
pObj Li st = new CDr awObj Li st ;Gl obObj Li st Map[ 1] =pObj Li st ;
}
voi d CSFCDoc: : OnFi l eNew( ){
/ / TODO: Add your command handl er code her eI ni t i al i ze( ) ;
}
/ / Cr eat e Met a Language Fi l e / /BOOL CSFCDoc: : Cr eat eMLF( LPCSTR l pszFi l eName){
CFi l e f i l e;BOOL bResul t = TRUE;CDr awObj * pObj ;
i f ( f i l e. Open ( l pszFi l eName, CFi l e: : modeCr eat e | CFi l e: : modeWr i t e) ){
CWai t Cur sor wai t ;CAr chi ve ar ( &f i l e, CAr chi ve: : st or e) ;
/ / SALVATAGGI O PROGETTO : I NFORMAZI ONI GENERALI / // / scor r e t ut t e l e l i st e
CDr awObj Li st * pPi vot Li st ;voi d * pTemp;WORD nSFC;CSt r i ng t xt ( ’ ’ BEGI N_PROJECT; \ n\ n’ ’ ) ;
ar . Wr i t e( LPCTSTR( t xt ) , t xt . Get Lengt h( ) ) ;
POSI TI ON pos1 = Gl obObj Li st Map. Get St ar t Posi t i on( ) ;whi l e ( pos1 ! = NULL){
Gl obObj Li st Map. Get Next Assoc( pos1, nSFC, pTemp) ;pPi vot Li st = ( CDr awObj Li st * ) pTemp;
226
t xt . For mat ( ’ ’ SFC %i : %s; \ n’ ’ , nSFC, names[ nSFC] ) ;ar . Wr i t e( LPCTSTR( t xt ) , t xt . Get Lengt h( ) ) ;
POSI TI ON pos = pPi vot Li st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;
/ / i ndi r i zzo assol ut o del l ’ ogget t ot xt = pObj - >Text ual For m( ) ;ar . Wr i t e( LPCTSTR( t xt ) , t xt . Get Lengt h( ) ) ;
}t xt = ’ ’ END_SFC; \ n\ n’ ’ ;ar . Wr i t e( LPCTSTR( t xt ) , t xt . Get Lengt h( ) ) ;
}t xt = ’ ’ END_PROJECT; ’ ’ ;ar . Wr i t e( LPCTSTR( t xt ) , t xt . Get Lengt h( ) ) ;
}el se{
CSt r i ng st r i ng;st r i ng. For mat ( ’ ’ Unabl e t o cr eat e %s’ ’ , l pszFi l eName) ;MessageBox ( NULL, st r i ng, ’ ’ Er r or ’ ’ , MB_I CONEXCLAMATI ON | MB_OK) ;bResul t = FALSE;
}
r et ur n bResul t ;
}
voi d CSFCDoc: : OnMLFCr eat e( ){
/ / check al l SFC;CDr awObj Li st * pOl dLi st = pObj Li st ;BOOL val i d = TRUE;POSI TI ON pos = Gl obObj Li st Map. Get St ar t Posi t i on( ) ;WORD n;voi d * pTemp;
whi l e ( pos ! = NULL){
Gl obObj Li st Map. Get Next Assoc( pos, n, pTemp) ;pObj Li st = ( CDr awObj Li st * ) pTemp;val i d = val i d && ( CheckSFC( ) ) ;
}
pObj Li st = pOl dLi st ;
i f ( val i d){
POSI TI ON pos = Get Fi r st Vi ewPosi t i on( ) ;CSFCVi ew* pVi ew;whi l e ( pos ! = NULL){
pVi ew = ( ( CSFCVi ew* ) Get Next Vi ew( pos) ) ;pVi ew- >m_pOut Dl g- >Dest r oyWi ndow( ) ;pVi ew- >bCheck = FALSE;
}
char szFi l t er s[ ] = ’ ’ ML f i l es ( * . ml f ) | * . ml f | Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
CFi l eDi al og dl g ( FALSE, ’ ’ ml f ’ ’ , m_st r MFLPat hName, OFN_OVERWRI TEPROMPT |OFN_PATHMUSTEXI ST | OFN_HI DEREADONLY, szFi l t er s, NULL) ;
227
i f ( dl g. DoModal ( ) == I DOK){
i f ( Cr eat eMLF ( dl g. Get Pat hName ( ) ) ){
m_st r MFLName = dl g. Get Fi l eTi t l e ( ) ;m_st r MFLPat hName = dl g. Get Pat hName ( ) ;
}}
}el se{
MessageBeep( 0) ;MessageBox( NULL, ’ ’ Synt ax er r or ( s) i n SFC’ ’ , ’ ’ ERROR ! ’ ’ , MB_OK |
MB_TASKMODAL) ;}
}voi d CSFCDoc: : OnSet DocSi ze( ){
/ / TODO: Add your command handl er code her eCDocPageDl g dl g;CSi ze newSi ze;
dl g. m_hei ght = m_si zeDoc[ Act i veSFC] . cy;dl g. m_wi dt h = m_si zeDoc[ Act i veSFC] . cx;
i f ( dl g. DoModal ( ) == I DOK){
/ / r et r i eve t he di al og dat anewSi ze. cy = dl g. m_hei ght ;newSi ze. cx = dl g. m_wi dt h;Updat eAl l Vi ews( NULL) ;i f ( newSi ze ! = m_si zeDoc[ Act i veSFC] ){
m_si zeDoc[ Act i veSFC] = newSi ze;POSI TI ON pos = Get Fi r st Vi ewPosi t i on( ) ;whi l e ( pos ! = NULL){
( ( CSFCVi ew* ) Get Next Vi ew( pos) ) - >Set PageSi ze( m_si zeDoc[ Act i veSFC] ) ;}
}}
}
BOOL CSFCDoc: : CheckSFC( ){
BOOL cor r ect = TRUE;CDr awObj * pObj ;CSFCVi ew * pVi ew;i nt war ni ngs, er r or s;i nt n_war n = 0, n_er r s = 0;
POSI TI ON pos1 = Get Fi r st Vi ewPosi t i on( ) ;whi l e ( pos1 ! = NULL)
pVi ew = ( CSFCVi ew* ) Get Next Vi ew( pos1) ;
i f ( pVi ew- >m_pOut Dl g- >Get Saf eHwnd( ) == 0)pVi ew- >m_pOut Dl g- >Cr eat e( ) ;
pVi ew- >bCheck = TRUE;
pVi ew- >m_pOut Dl g- >m_r esul t s = ’ ’ ’ ’ ;CSt r i ng war , er r ;CSt r i ng obj ;
228
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;i nt t ot = pObj Li st - >Get Count ( ) ;
i nt n = 0;whi l e ( pos ! = NULL){
n++;pVi ew- >m_pOut Dl g- >m_pr og. Set Pos( n* 100/ t ot ) ;pObj = pObj Li st - >Get Next ( pos) ;cor r ect &= pObj - >Check( war ni ngs, er r or s) ;i f ( ( war ni ngs | er r or s) && ( pObj - >m_Type ! = Ar Obj ) ){
i f ( war ni ngs)n_war n++;
i f ( er r or s)n_er r s++;
war = War ni ngSt r ( war ni ngs) ;er r = Er r or St r ( er r or s) ;swi t ch ( pObj - >m_Type) {case PhObj :{
CPhaseObj * pPhObj = ( CPhaseObj * ) pObj ;obj . For mat ( ’ ’ S%i : ’ ’ , Act i veSFC* 100+pPhObj - >m_number ) ;
CMul t i Obj * pMul t i Obj = ( CMul t i Obj * ) pObj ;obj . For mat ( ’ ’ Sel ect : ’ ’ ) ;
}br eak;case SYNCRO:{
CMul t i Obj * pMul t i Obj = ( CMul t i Obj * ) pObj ;obj . For mat ( ’ ’ Syncr o : ’ ’ ) ;
}br eak;case PARALLEL:{
CMul t i Obj * pMul t i Obj = ( CMul t i Obj * ) pObj ;obj . For mat ( ’ ’ Par al l el : ’ ’ ) ;
}br eak;case CONVERGENCE:{
CMul t i Obj * pMul t i Obj = ( CMul t i Obj * ) pObj ;obj . For mat ( ’ ’ Conver gence : ’ ’ ) ;
}br eak;
}i f ( war ni ngs){
pVi ew- >m_pOut Dl g- >m_r esul t s += obj ;pVi ew- >m_pOut Dl g- >m_r esul t s += war ;
}i f ( er r or s){
229
pVi ew- >m_pOut Dl g- >m_r esul t s += obj ;pVi ew- >m_pOut Dl g- >m_r esul t s += er r ;
}pVi ew- >m_pOut Dl g- >Updat eDat a( FALSE) ;
}
}
er r . For mat ( ’ ’ \ r \ n Er r or s : %i - War ni ngs : %i ’ ’ , n_er r s, n_war n) ;pVi ew- >m_pOut Dl g- >m_r esul t s += er r ;
i f ( ! cor r ect ){
er r . For mat ( ’ ’ \ r \ n ERRORS ! ! ! ’ ’ ) ;pVi ew- >m_pOut Dl g- >m_r esul t s += er r ;
}
pVi ew- >m_pOut Dl g- >Updat eDat a( FALSE) ;
r et ur n cor r ect ;}
voi d CSFCDoc: : OnCheckBut t on( ){
/ / TODO: Add your command handl er code her eCheckSFC( ) ;
}
CSt r i ng CSFCDoc: : War ni ngSt r ( i nt war ){
CSt r i ng t xt ;
t xt = ’ ’ ’ ’ ;i f ( war & WN_UPLNKFLOAT)
t xt = ’ ’ War ni ng : Upper Li nk i s f l oat i ng\ r \ n’ ’ ;i f ( war & WN_DWLNKFLOAT)
t xt = ’ ’ War ni ng : Lower Li nk i s f l oat i ng\ r \ n’ ’ ;
r et ur n t xt ;}
CSt r i ng CSFCDoc: : Er r or St r ( i nt er r ){
CSt r i ng t xt ;
t xt = ’ ’ ’ ’ ;i f ( er r & ER_DWLNKNOTCOMP)
t xt += ’ ’ Er r or : Lower Li nk i s not compat i bl e\ r \ n’ ’ ;i f ( er r & ER_UPLNKNOTCOMP)
t xt += ’ ’ Er r or : Upper Li nk i s not compat i bl e\ r \ n’ ’ ;i f ( er r & ER_AMBI GFLOW)
t xt += ’ ’ Er r or : Ambi gui t y f l ow pr ogr am\ r \ n’ ’ ;i f ( er r & ER_UPFLOWERROR)
t xt += ’ ’ Mul t i : Er r or : One of t he Upper Li nk pr esent a not compat i bl e f l ow\ r \ n’ ’ ;i f ( er r & ER_DWFLOWERROR)
t xt += ’ ’ Mul t i : Er r or : One of t he Lower Li nk pr esent a not compat i bl e f l ow\ r \ n’ ’ ;i f ( er r & ER_I NCOMPLI NK)
t xt += ’ ’ Er r or : I ncompl et e Li nks\ r \ n’ ’ ;i f ( er r & ER_OBJFLOATI NG)
t xt += ’ ’ Er r or : Obj ect i s f l oat i ng\ r \ n’ ’ ;
r et ur n t xt ;}
voi d CSFCDoc: : OnI mpor t But t on( )
230
{/ / TODO: Add your command handl er code her echar szFi l t er s[ ] = ’ ’ ML f i l es ( * . ml f ) | * . ml f | Al l f i l es ( * . * ) | * . * | | ’ ’ ;CSt r i ng f i l ename;
/ / MessageBeep( 0) ;
CFi l eDi al og dl g ( TRUE, ’ ’ ml f ’ ’ , m_st r MFLPat hName, OFN_FI LEMUSTEXI ST |OFN_HI DEREADONLY, szFi l t er s, NULL) ;
i f ( dl g. DoModal ( ) == I DOK){
i f ( I mpor t MLF ( dl g. Get Pat hName ( ) ) ){
m_st r MFLName = dl g. Get Fi l eTi t l e ( ) ;m_st r MFLPat hName = dl g. Get Pat hName ( ) ;
}}
}
BOOL CSFCDoc: : I mpor t MLF( LPCSTR l pszFi l eName){
CSt di oFi l e f i l e;BOOL bResul t = TRUE;
i f ( f i l e. Open ( l pszFi l eName, CFi l e: : modeRead | CFi l e: : t ypeText ) ){
CWai t Cur sor wai t ;
CSt r i ng t xt , t emp;BOOL cont = TRUE;whi l e ( cont ){
cont = f i l e. ReadSt r i ng( t emp) ;t xt += t emp;
}Del et eAl l SFC( ) ;
DWORD l engt h = t xt . Get Lengt h( ) ;char * p_buf = ( char * ) mal l oc( l engt h) ;LPTSTR p = t xt . Get Buf f er ( 1) ;memcpy( p_buf , p, l engt h) ;t xt . Rel easeBuf f er ( ) ;
CGr aph gr aph;gr aph. Bui l dPr j ( p_buf , l engt h) ;
f r ee( p_buf ) ;
/ / updat e document di mensi onCDr awObj Li st * pLi st ;POSI TI ON pos1 = Gl obObj Li st Map. Get St ar t Posi t i on( ) ;WORD n;voi d * pTemp;
whi l e ( pos1 ! = NULL){
Gl obObj Li st Map. Get Next Assoc( pos1, n, pTemp) ;pLi st = ( CDr awObj Li st * ) pTemp;i nt dx = - 10000, bt = - 10000;POSI TI ON pos = pLi st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
CDr awObj * pObj = pLi st - >Get Next ( pos) ;
231
i f ( pObj - >m_posi t i on. x > dx)dx = pObj - >m_posi t i on. x;
i f ( pObj - >m_posi t i on. y > bt )bt = pObj - >m_posi t i on. y;
}i f ( ( dx+5) * m_gr i d/ 10 > m_si zeDoc[ n] . cx)
m_si zeDoc[ n] . cx = ( dx+5) * m_gr i d/ 10;i f ( ( bt +5) * m_gr i d/ 10 > m_si zeDoc[ n] . cy)
m_si zeDoc[ n] . cy = ( bt +5) * m_gr i d/ 10;}
Updat eAl l Vi ews( FALSE) ;}el se{
CSt r i ng st r i ng;st r i ng. For mat ( ’ ’ Unabl e t o open %s’ ’ , l pszFi l eName) ;MessageBox ( NULL, st r i ng, ’ ’ Er r or ’ ’ , MB_I CONEXCLAMATI ON | MB_OK) ;bResul t = FALSE;
#i f ! def i ned( AFX_SFCVI EW_H__39DB610C_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)#def i ne AFX_SFCVI EW_H__39DB610C_E601_11D2_B1B8_EDD329A68936__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CCheckDl g;
/ / Hi nt s f or Updat eAl l Vi ews/ OnUpdat e#def i ne HI NT_UPDATE_WI NDOW 0#def i ne HI NT_UPDATE_DRAWOBJ 1#def i ne HI NT_UPDATE_SELECTI ON 2#def i ne HI NT_UPDATE_LI ST 3
cl ass CSFCVi ew : publ i c CScr ol l Vi ew{pr ot ect ed: / / cr eat e f r om ser i al i zat i on onl y
CSFCVi ew( ) ;DECLARE_DYNCREATE( CSFCVi ew)
232
publ i c:
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CSFCVi ew)publ i c:vi r t ual voi d OnDr aw( CDC* pDC) ; / / over r i dden t o dr aw t hi s vi ewvi r t ual BOOL Pr eCr eat eWi ndow( CREATESTRUCT& cs) ;vi r t ual voi d OnI ni t i al Updat e( ) ;vi r t ual voi d OnPr epar eDC( CDC* pDC, CPr i nt I nf o* pI nf o = NULL) ;pr ot ect ed:vi r t ual BOOL OnPr epar ePr i nt i ng( CPr i nt I nf o* pI nf o) ;vi r t ual voi d OnBegi nPr i nt i ng( CDC* pDC, CPr i nt I nf o* pI nf o) ;vi r t ual voi d OnEndPr i nt i ng( CDC* pDC, CPr i nt I nf o* pI nf o) ;vi r t ual voi d OnUpdat e( CVi ew* pSender , LPARAM l Hi nt , CObj ect * pHi nt ) ;vi r t ual voi d OnPr i nt ( CDC* pDC, CPr i nt I nf o* pI nf o) ;/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpubl i c:
/ / member var i abl esBOOL bCheck;BOOL m_pl aci ng;doubl e m_pr i nt Scal e;UI NT m_zoomI D;doubl e m_zoom;CCheckDl g* m_pOut Dl g;CDr awObj Li st m_sel ect i on;CDr awPoi nt Li st Ref m_pt Sel ect i on;CDr awPoi nt Li st m_pt Li nk;
/ / member f unct i onCSFCDoc* Get Document ( ) ;voi d DocToCl i ent ( CRect & r ect ) ;voi d DocToCl i ent ( CPoi nt & poi nt ) ;voi d Cl i ent ToDoc( CPoi nt & poi nt ) ;voi d Cl i ent ToDoc( CRect & r ect ) ;voi d Set PageSi ze( CSi ze si ze) ;voi d Dr awGr i d( CDC* pDC) ;st at i c CPoi nt Near est OnGr i d( CPoi nt poi nt ) ;voi d I nval Obj ( CDr awObj * pObj ) ;voi d I nval Ar c( CAr cObj * pObj , i nt segment s) ;vi r t ual ~CSFCVi ew( ) ;
#i f def _DEBUGvi r t ual voi d Asser t Val i d( ) const ;vi r t ual voi d Dump( CDumpCont ext & dc) const ;
#endi f
/ / Gener at ed message map f unct i onspr ot ect ed:
/ / { { AFX_MSG( CSFCVi ew)af x_msg voi d OnLBut t onDown( UI NT nFl ags, CPoi nt poi nt ) ;af x_msg voi d OnMouseMove( UI NT nFl ags, CPoi nt poi nt ) ;af x_msg voi d OnLBut t onUp( UI NT nFl ags, CPoi nt poi nt ) ;af x_msg voi d OnSel But t on( ) ;af x_msg voi d OnAr cBut t on( ) ;af x_msg voi d OnUpdat eAr cBut t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnPhaseBut t on( ) ;af x_msg voi d OnUpdat ePhaseBut t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnPhase0But t on( ) ;af x_msg voi d OnUpdat ePhase0But t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnTr ansBut t on( ) ;af x_msg voi d OnLBut t onDbl Cl k( UI NT nFl ags, CPoi nt poi nt ) ;af x_msg voi d OnRBut t onDown( UI NT nFl ags, CPoi nt poi nt ) ;af x_msg voi d OnMul t i 1but t on( ) ;
233
af x_msg voi d OnUpdat eMul t i 1but t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnMul t i 2but t on( ) ;af x_msg voi d OnUpdat eMul t i 2but t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnMul t i 3but t on( ) ;af x_msg voi d OnUpdat eMul t i 3but t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnMul t i 4but t on( ) ;af x_msg voi d OnUpdat eMul t i 4but t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnCancel ( ) ;af x_msg voi d OnZoom( UI NT nI D) ;af x_msg voi d OnUpdat eZoomUI ( CCmdUI * pCmdUI ) ;af x_msg voi d OnUpdat eExpandSwi t ch( CCmdUI * pCmdUI ) ;af x_msg voi d OnExpandSwi t ch( ) ;af x_msg voi d OnRf r shBut t on( ) ;af x_msg voi d OnPageSet up( ) ;af x_msg voi d OnUpdat eCheckBut t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnUpdat eSel But t on( CCmdUI * pCmdUI ) ;af x_msg voi d OnUpdat eTr ansBut t on( CCmdUI * pCmdUI ) ;/ / } } AFX_MSG/ / user def i nedaf x_msg LRESULT OnGoodbye( WPARAM wPar am, LPARAM l Par am) ;af x_msg LRESULT OnCheckAgai n( WPARAM wPar am, LPARAM l Par am) ;
DECLARE_MESSAGE_MAP( )
} ;
#i f ndef _DEBUG / / debug ver si on i n SFCVi ew. cppi nl i ne CSFCDoc* CSFCVi ew: : Get Document ( )
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_SFCVI EW_H__39DB610C_E601_11D2_B1B8_EDD329A68936__I NCLUDED_)
File : SFCDlg.h/ / SFCVi ew. cpp : i mpl ement at i on of t he CSFCVi ew cl ass/ /
BEGI N_MESSAGE_MAP( CSFCVi ew, CScr ol l Vi ew)ON_MESSAGE( WM_GOODBYE, OnGoodbye )ON_MESSAGE( WM_CHECK_AGAI N, OnCheckAgai n )/ / { { AFX_MSG_MAP( CSFCVi ew)ON_WM_LBUTTONDOWN( )ON_WM_MOUSEMOVE( )ON_WM_LBUTTONUP( )ON_COMMAND( I D_SEL_BUTTON, OnSel But t on)ON_COMMAND( I D_ARC_BUTTON, OnAr cBut t on)ON_UPDATE_COMMAND_UI ( I D_ARC_BUTTON, OnUpdat eAr cBut t on)ON_COMMAND( I D_PHASE_BUTTON, OnPhaseBut t on)ON_UPDATE_COMMAND_UI ( I D_PHASE_BUTTON, OnUpdat ePhaseBut t on)ON_COMMAND( I D_PHASE0_BUTTON, OnPhase0But t on)ON_UPDATE_COMMAND_UI ( I D_PHASE0_BUTTON, OnUpdat ePhase0But t on)ON_COMMAND( I D_TRANS_BUTTON, OnTr ansBut t on)ON_WM_LBUTTONDBLCLK( )ON_WM_RBUTTONDOWN( )ON_COMMAND( I D_MULTI _1BUTTON, OnMul t i 1but t on)ON_UPDATE_COMMAND_UI ( I D_MULTI _1BUTTON, OnUpdat eMul t i 1but t on)ON_COMMAND( I D_MULTI _2BUTTON, OnMul t i 2but t on)ON_UPDATE_COMMAND_UI ( I D_MULTI _2BUTTON, OnUpdat eMul t i 2but t on)ON_COMMAND( I D_MULTI _3BUTTON, OnMul t i 3but t on)ON_UPDATE_COMMAND_UI ( I D_MULTI _3BUTTON, OnUpdat eMul t i 3but t on)ON_COMMAND( I D_MULTI _4BUTTON, OnMul t i 4but t on)ON_UPDATE_COMMAND_UI ( I D_MULTI _4BUTTON, OnUpdat eMul t i 4but t on)ON_COMMAND_RANGE( I DM_ZOOM_41, I DM_ZOOM_14, OnZoom)ON_UPDATE_COMMAND_UI _RANGE( I DM_ZOOM_41, I DM_ZOOM_14, OnUpdat eZoomUI )ON_UPDATE_COMMAND_UI ( I D_EXPAND_SWI TCH, OnUpdat eExpandSwi t ch)ON_COMMAND( I D_EXPAND_SWI TCH, OnExpandSwi t ch)ON_COMMAND( I D_RFRSH_BUTTON, OnRf r shBut t on)ON_COMMAND( I D_PAGE_SETUP, OnPageSet up)ON_UPDATE_COMMAND_UI ( I D_CHECK_BUTTON, OnUpdat eCheckBut t on)ON_UPDATE_COMMAND_UI ( I D_SEL_BUTTON, OnUpdat eSel But t on)ON_COMMAND( I D_CANCEL, OnCancel )ON_UPDATE_COMMAND_UI ( I D_TRANS_BUTTON, OnUpdat eTr ansBut t on)/ / } } AFX_MSG_MAP/ / St andar d pr i nt i ng commandsON_COMMAND( I D_FI LE_PRI NT, CVi ew: : OnFi l ePr i nt )ON_COMMAND( I D_FI LE_PRI NT_DI RECT, CVi ew: : OnFi l ePr i nt )ON_COMMAND( I D_FI LE_PRI NT_PREVI EW, CVi ew: : OnFi l ePr i nt Pr evi ew)/ / user def i ned message map
CDC dc;CDC* pDr awDC = pDC;CBi t map bi t map;CBi t map* pOl dBi t map;
/ / onl y pai nt t he r ect t hat needs r epai nt i ngCRect cl i ent ;pDC- >Get Cl i pBox( cl i ent ) ;CRect r ect = cl i ent ;DocToCl i ent ( r ect ) ;
i f ( ! pDC- >I sPr i nt i ng( ) ){
/ / dr aw t o of f scr een bi t map f or f ast l ooki ng r epai nt si f ( dc. Cr eat eCompat i bl eDC( pDC) ){
i f ( bi t map. Cr eat eCompat i bl eBi t map( pDC, r ect . Wi dt h( ) , r ect . Hei ght ( ) ) ){
OnPr epar eDC( &dc, NULL) ;pDr awDC = &dc;
/ / of f set or i gi n mor e because bi t map i s j ust pi ece of t he whol e dr awi ngdc. Of f set Vi ewpor t Or g( - r ect . l ef t , - r ect . t op) ;pOl dBi t map = dc. Sel ect Obj ect ( &bi t map) ;dc. Set Br ushOr g( r ect . l ef t % 8, r ect . t op % 8) ;
/ / mi ght as wel l cl i p t o t he same r ect angl edc. I nt er sect Cl i pRect ( cl i ent ) ;
pDC- >Set Vi ewpor t Or g( 0, 0) ;pDC- >Set Wi ndowOr g( 0, 0) ;pDC- >Set MapMode( MM_TEXT) ;dc. Set Vi ewpor t Or g( 0, 0) ;dc. Set Wi ndowOr g( 0, 0) ;dc. Set MapMode( MM_TEXT) ;pDC- >Bi t Bl t ( r ect . l ef t , r ect . t op, r ect . Wi dt h( ) , r ect . Hei ght ( ) ,
&dc, 0, 0, SRCCOPY) ;dc. Sel ect Obj ect ( pOl dBi t map) ;
nPages. cx = ( i nt ) cei l ( ( doubl e) DocSi ze. cx* m_pr i nt Scal e/ ( doubl e) PageSi ze. cx) ;nPages. cy = ( i nt ) cei l ( ( doubl e) DocSi ze. cy* m_pr i nt Scal e/ ( doubl e) PageSi ze. cy) ;
237
pI nf o- >Set MaxPage( nPages. cx* nPages. cy) ;
CScr ol l Vi ew: : OnBegi nPr i nt i ng( pDC, pI nf o) ;
/ / check page si ze - - user coul d have gone i nt o pr i nt set up/ / f r om pr i nt di al og and changed paper or or i ent at i on
}
voi d CSFCVi ew: : OnEndPr i nt i ng( CDC* / * pDC* / , CPr i nt I nf o* / * pI nf o* / ){
m_Obj Tool = sel ect i on;m_pl aci ng = FALSE;m_pt Li nk. RemoveAl l ( ) ;m_zoom = 1;m_zoomI D = 32786;m_pr i nt Scal e = 1. 0;bCheck = FALSE;
CSi ze si ze = Get Document ( ) - >Get DocSi ze( ) ;CCl i ent DC dc( NULL) ;si ze. cx = Mul Di v( si ze. cx, dc. Get Devi ceCaps( LOGPI XELSX) , 100) ;si ze. cy = Mul Di v( si ze. cy, dc. Get Devi ceCaps( LOGPI XELSY) , 100) ;Set Scr ol l Si zes( MM_TEXT, si ze) ;
}
voi d CSFCVi ew: : Set PageSi ze( CSi ze si ze){
CCl i ent DC dc( NULL) ;si ze. cx = Mul Di v( si ze. cx, dc. Get Devi ceCaps( LOGPI XELSX) , 100) ;si ze. cy = Mul Di v( si ze. cy, dc. Get Devi ceCaps( LOGPI XELSY) , 100) ;Set Scr ol l Si zes( MM_TEXT, si ze) ;
/ / MessageBeep( 0) ;Get Document ( ) - >Updat eAl l Vi ews( NULL) ;
}
voi d CSFCVi ew: : OnMouseMove( UI NT nFl ags, CPoi nt poi nt ){
CPoi nt k, t emp;t emp = poi nt ;Cl i ent ToDoc( t emp) ;k=Near est OnGr i d( t emp) ;swi t ch( m_Obj Tool ){case sel ect i on:
CSel ect Tool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case ar c:CAr cTool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
239
case phase:CPhaseTool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case phase0:CPhaseTool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case t r ansi t i on:CTr ansTool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 1:CMul t i Tool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 2:CMul t i Tool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 3:CMul t i Tool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 4:CMul t i Tool : : OnMouseMove( t hi s, nFl ags, poi nt ) ;br eak;
}
CScr ol l Vi ew: : OnMouseMove( nFl ags, poi nt ) ;}
voi d CSFCVi ew: : OnLBut t onUp( UI NT nFl ags, CPoi nt poi nt ){
/ / TODO: Add your message handl er code her e and/ or cal l def aul tswi t ch( m_Obj Tool ){case sel ect i on:
{CSel ect Tool : : OnLBut t onUp( t hi s, nFl ags, poi nt ) ;
}br eak;
}
CScr ol l Vi ew: : OnLBut t onUp( nFl ags, poi nt ) ;}
voi d CSFCVi ew: : OnUpdat e( CVi ew* pSender , LPARAM l Hi nt , CObj ect * pHi nt ){
swi t ch ( l Hi nt ){case HI NT_UPDATE_WI NDOW: / / r edr aw ent i r e wi ndow
I nval i dat e( FALSE) ;br eak;
case HI NT_UPDATE_DRAWOBJ: / / a si ngl e obj ect has changed{
CDr awObj * pObj = ( CDr awObj * ) pHi nt ;i f ( pObj - >m_Type == Ar Obj )
I nval Ar c( ( CAr cObj * ) pObj , - 1) ;el se
I nval Obj ( pObj ) ;
240
}br eak;
case HI NT_UPDATE_SELECTI ON: / / an ent i r e sel ect i on has changed{
CDr awObj Li st * pLi st = pHi nt ! = NULL ?( CDr awObj Li st * ) pHi nt : &m_sel ect i on;
POSI TI ON pos = pLi st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL)
I nval Obj ( pLi st - >Get Next ( pos) ) ;}br eak;
case HI NT_UPDATE_LI ST: / / t he ent i r e LI ST has changed{
POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;whi l e ( pos ! = NULL){
CDr awObj * pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type ! = Ar Obj )
I nval Obj ( pObj ) ;el se
I nval Ar c( ( CAr cObj * ) pObj , - 1) ;}
}br eak;
def aul t :ASSERT( FALSE) ;br eak;
}
}
voi d CSFCVi ew: : I nval Obj ( CDr awObj * pObj ){
CRect r ect = pObj - >m_r ect ;DocToCl i ent ( r ect ) ;
r ect . I nf l at eRect ( m_gr i d, m_gr i d) ; / / r i - di segna i nt or no al l ’ ogget t oI nval i dat eRect ( r ect , FALSE) ;
}
/ / r i di segna un numer o speci f i cat o di segment i del l ’ ar co a/ / par t i r e dal l ’ ul t i movoi d CSFCVi ew: : I nval Ar c( CAr cObj * pObj , i nt segment s){
i nt n = pObj - >m_nPoi nt s;i nt seg = segment s;i f ( seg == - 1)
seg = pObj - >m_nPoi nt s- 1;i nt i = 0;CRect r ect ;CPoi nt pnt 1, pnt 2;
CCl i ent DC dc( t hi s) ;
i f ( ( seg > n) | | ( n < 2) )r et ur n;
whi l e ( i < seg){
pnt 1 = pObj - >m_poi nt s[ n - i - 1] ;pnt 2 = pObj - >m_poi nt s[ n - i - 2] ;r ect . Set Rect ( pnt 1. x* m_gr i d, pnt 1. y* m_gr i d, pnt 2. x* m_gr i d, pnt 2. y* m_gr i d) ;
241
r ect . Nor mal i zeRect ( ) ;r ect . I nf l at eRect ( m_gr i d, m_gr i d) ;DocToCl i ent ( r ect ) ; / / r i - di segna i nt or no al l ’ ogget t oI nval i dat eRect ( r ect , FALSE) ;i ++;
}}
voi d CSFCVi ew: : Cl i ent ToDoc( CPoi nt & poi nt ){
CCl i ent DC dc( t hi s) ;OnPr epar eDC( &dc, NULL) ;dc. DPt oLP( &poi nt ) ;
}
voi d CSFCVi ew: : Cl i ent ToDoc( CRect & r ect ){
CCl i ent DC dc( t hi s) ;OnPr epar eDC( &dc, NULL) ;dc. DPt oLP( r ect ) ;
}
voi d CSFCVi ew: : DocToCl i ent ( CPoi nt & poi nt ){
CCl i ent DC dc( t hi s) ;OnPr epar eDC( &dc, NULL) ;dc. LPt oDP( &poi nt ) ;
}
voi d CSFCVi ew: : DocToCl i ent ( CRect & r ect ){
CCl i ent DC dc( t hi s) ;OnPr epar eDC( &dc, NULL) ;dc. LPt oDP( r ect ) ;r ect . Nor mal i zeRect ( ) ;
}
voi d CSFCVi ew: : OnSel But t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = sel ect i on;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = FALSE;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnUpdat eSel But t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == sel ect i on) ;
}
voi d CSFCVi ew: : OnPhase0But t on( )
242
{/ / TODO: Add your command handl er code her em_Obj Tool = phase0;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CPhaseTool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , TRUE) ;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnPhaseBut t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = phase;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CPhaseTool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , FALSE) ;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnTr ansBut t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = t r ansi t i on;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CTr ansTool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) ) ;m_sel ect i on. RemoveAl l ( ) ;
243
m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnAr cBut t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = ar c;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = FALSE;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnUpdat ePhase0But t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == phase0) ;
}
voi d CSFCVi ew: : OnUpdat ePhaseBut t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == phase) ;
}
voi d CSFCVi ew: : OnUpdat eTr ansBut t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == t r ansi t i on) ;
}
voi d CSFCVi ew: : OnUpdat eAr cBut t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == ar c) ;
}
voi d CSFCVi ew: : OnUpdat eMul t i 1but t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == mul t i 1) ;
}
voi d CSFCVi ew: : OnUpdat eMul t i 2but t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == mul t i 2) ;
}
voi d CSFCVi ew: : OnUpdat eMul t i 3but t on( CCmdUI * pCmdUI ){
244
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == mul t i 3) ;
}
voi d CSFCVi ew: : OnUpdat eMul t i 4but t on( CCmdUI * pCmdUI ){
/ / TODO: Add your command updat e UI handl er code her epCmdUI - >Set Check( m_Obj Tool == mul t i 4) ;
}
CPoi nt CSFCVi ew: : Near est OnGr i d( CPoi nt poi nt ) / / Coor ds must be i n Doc ambi ent{
i nt x, y;doubl e q, r , f ;
q = poi nt . y / m_gr i d;r = poi nt . y % m_gr i d;f = r / m_gr i d;y = ( f < 0. 5) ? ( i nt ) ( q) : ( i nt ) ( q+1) ;
q = poi nt . x / m_gr i d;r = poi nt . x % m_gr i d;f = r / m_gr i d;x = ( f < 0. 5) ? ( i nt ) ( q) : ( i nt ) ( q+1) ;
r et ur n CPoi nt ( x, y) ;}
voi d CSFCVi ew: : OnLBut t onDbl Cl k( UI NT nFl ags, CPoi nt poi nt ){
/ / TODO: Add your message handl er code her e and/ or cal l def aul tswi t ch( m_Obj Tool ){case sel ect i on:
{CSel ect Tool : : OnLBut t onDbl Cl k( t hi s, nFl ags, poi nt ) ;
}br eak;
}
CScr ol l Vi ew: : OnLBut t onDbl Cl k( nFl ags, poi nt ) ;}
voi d CSFCVi ew: : OnRBut t onDown( UI NT nFl ags, CPoi nt poi nt ){
/ / TODO: Add your message handl er code her e and/ or cal l def aul tswi t ch( m_Obj Tool ){case phase0:
CPhaseTool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case phase:CPhaseTool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case t r ansi t i on:CTr ansTool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case ar c:{
CAr cTool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;
245
}
case mul t i 1:CMul t i Tool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 2:CMul t i Tool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 3:CMul t i Tool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
case mul t i 4:CMul t i Tool : : OnRBut t onDown( t hi s, nFl ags, poi nt ) ;br eak;
}
CScr ol l Vi ew: : OnRBut t onDown( nFl ags, poi nt ) ;}
voi d CSFCVi ew: : OnMul t i 1but t on( ){
m_Obj Tool = mul t i 1;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CMul t i Tool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , SELECT) ;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnMul t i 2but t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = mul t i 2;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CMul t i Tool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , PARALLEL) ;m_sel ect i on. RemoveAl l ( ) ;
246
m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnMul t i 3but t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = mul t i 3;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CMul t i Tool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , CONVERGENCE) ;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnMul t i 4but t on( ){
/ / TODO: Add your command handl er code her em_Obj Tool = mul t i 4;
i f ( m_pl aci ng){
i f ( ! pObj Li st - >I sEmpt y( ) ) ;{
CDr awObj * pObj ;pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;
}}
m_pl aci ng = TRUE;CMul t i Tool : : OnNewObj ( t hi s, CPoi nt ( 2* m_di m, 2* m_di m) , SYNCRO) ;m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnCancel ( ){
/ / TODO: Add your command handl er code her ePOSI TI ON pos1;POSI TI ON pos = m_sel ect i on. Get HeadPosi t i on( ) ;CDr awObj * pObj ;
/ / Ri muove pr i ma gl i ar chi per el i mi nar e cor r et t ament e/ / i col l egament i con gl i al t r i ogget t i .whi l e ( pos ! = NULL){
247
pos1 = pos;pObj = m_sel ect i on. Get Next ( pos) ;i f ( pObj - >m_Type == Ar Obj ){
Get Document ( ) - >Remove( pObj ) ;pObj - >Remove( ) ;m_sel ect i on. RemoveAt ( pos1) ;
}}
pos = m_sel ect i on. Get HeadPosi t i on( ) ;
whi l e ( pos ! = NULL){
pObj = m_sel ect i on. Get Next ( pos) ;Get Document ( ) - >Remove( pObj ) ;pObj - >Remove( ) ;
}
m_sel ect i on. RemoveAl l ( ) ;m_pt Sel ect i on. RemoveAl l ( ) ;m_pt Li nk. RemoveAl l ( ) ;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnPr epar eDC( CDC* pDC, CPr i nt I nf o* pI nf o){
/ / TODO: Add your speci al i zed code her e and/ or cal l t he base cl ass
CScr ol l Vi ew: : OnPr epar eDC( pDC, pI nf o) ;
/ / mappi ng mode i s MM_ANI SOTROPI C/ / t hese ext ent s set up a mode si mi l ar t o MM_LOENGLI SH
pDC- >Set MapMode( MM_I SOTROPI C) ;
doubl e x, y;i nt nx, ny;i nt of sx, of sy;CSi ze si zeDoc = Get Document ( ) - >m_si zeDoc[ Act i veSFC] ;doubl e zoom;i f ( pDC- >I sPr i nt i ng( ) ){
of sx = ( i nt ) ( ( doubl e) pDC- >Get Devi ceCaps( HORZSI ZE) * 10. 0/ m_pr i nt Scal e) ;of sy = ( i nt ) ( ( doubl e) pDC- >Get Devi ceCaps( VERTSI ZE) * 10. 0/ m_pr i nt Scal e) ;nx = ( i nt ) ( ( pI nf o- >m_nCur Page- 1) % nPages. cx) ;ny = ( i nt ) ( ( pI nf o- >m_nCur Page- 1) / nPages. cx) ;
pDC- >Set Wi ndowExt ( si zeDoc. cx, si zeDoc. cy) ;pDC- >Set Vi ewpor t Ext ( ( i nt ) ( ( doubl e) si zeDoc. cx* m_pr i nt Scal e/ x) ,
( i nt ) ( ( doubl e) si zeDoc. cy* m_pr i nt Scal e/ y) ) ;
pDC- >Set Wi ndowOr g( nx * of sx, ny * of sy) ;}el se{
248
zoom = m_zoom;/ / pi xel per mi l l i met r o SU UN 15’ ’x = 2800. 0/ ( doubl e) pDC- >Get Devi ceCaps( HORZRES) ;y = 2100. 0/ ( doubl e) pDC- >Get Devi ceCaps( VERTRES) ;pDC- >Set Wi ndowExt ( si zeDoc. cx, si zeDoc. cy) ;pDC- >Set Vi ewpor t Ext ( ( i nt ) ( ( doubl e) si zeDoc. cx/ x* zoom) ,
( i nt ) ( ( doubl e) si zeDoc. cy/ y* zoom) ) ;CSi ze si ze;si ze. cx = ( i nt ) ( ( doubl e) si zeDoc. cx* 10. 0/ x* zoom) ;si ze. cy = ( i nt ) ( ( doubl e) si zeDoc. cy* 10. 0/ y* zoom) ;Set Scr ol l Si zes( MM_TEXT, si ze) ;
CRect r ect ;r ect . l ef t = 0;r ect . bot t om = 0;r ect . r i ght = pDoc- >Get DocSi ze( ) . cx* 10;r ect . t op = pDoc- >Get DocSi ze( ) . cy* 10;
pDC- >Set BkMode( TRANSPARENT) ;pDC- >Rect angl e( r ect ) ;r ect . Nor mal i zeRect ( ) ;
CRect cl i pRect ;Get Cl i ent Rect ( cl i pRect ) ;Cl i ent ToDoc( cl i pRect ) ;cl i pRect . Nor mal i zeRect ( ) ;
CPoi nt UpLef t , Bot t Ri ght ;CPoi nt DocBot t Ri ght ;UpLef t = Near est OnGr i d( cl i pRect . TopLef t ( ) ) ;Bot t Ri ght = Near est OnGr i d( cl i pRect . Bot t omRi ght ( ) ) ;DocBot t Ri ght = Near est OnGr i d( r ect . Bot t omRi ght ( ) ) ;
i nt del t a;
i f ( m_zoom < 0. 5)del t a = 2;
el sedel t a = 1;
CPoi nt poi nt ;i nt x = UpLef t . x;i nt y = UpLef t . y;
whi l e ( ( y < Bot t Ri ght . y) && ( y < DocBot t Ri ght . y) ){
whi l e ( ( x < Bot t Ri ght . x) && ( x < DocBot t Ri ght . x) ){
poi nt = CPoi nt ( x* m_gr i d, y* m_gr i d) ;pDC- >Set Pi xel V( poi nt . x, poi nt . y, RGB( 200, 0, 0) ) ;x += del t a;
}x = UpLef t . x;y += del t a;
}
249
pDC- >Sel ect Obj ect ( pOl dPen) ;}
voi d CSFCVi ew: : OnZoom( UI NT nI D){
/ / TODO: Add your command handl er code her e
m_zoomI D = nI D;m_zoom = ( doubl e) ( abs( nI D- 32786) / 2. 0+1) ;i f ( ( i nt ) ( nI D- 32786) < 0)
m_zoom = 1/ m_zoom;I nval i dat e( ) ;
}
voi d CSFCVi ew: : OnUpdat eZoomUI ( CCmdUI * pCmdUI ){
#i f ! def i ned( AFX_TI ME_H__D33061E2_5495_11D3_8FB1_C5834F367878__I NCLUDED_)#def i ne AFX_TI ME_H__D33061E2_5495_11D3_8FB1_C5834F367878__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CTi mer : publ i c CObj ect{publ i c:
CTi mer ( ) ;DECLARE_SERI AL ( CTi mer )
~CTi mer ( ) ;CSt r i ng Ti meSt r i ng( ) ;
publ i c:voi d St r i ng2Ti me( CSt r i ng t m) ;vi r t ual voi d Ser i al i ze( CAr chi ve & ar ) ;
i nt d;i nt h;i nt m;i nt s;i nt ms;
} ;
#endi f / / ! def i ned( AFX_TI ME_H__D33061E2_5495_11D3_8FB1_C5834F367878__I NCLUDED_)
File : Time.cpp/ / Ti me. cpp: i mpl ement at i on of t he CTi me cl ass./ // / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
CSt r i ng t i me;t i me. For mat ( ’ ’ T#%i d_%i h_%i m_%i s_%i ms’ ’ , d, h, m, s, ms) ;
r et ur n t i me;}
voi d CTi mer : : Ser i al i ze( CAr chi ve & ar ){
i f ( ar . I sSt or i ng( ) )ar << d << h << m << s << ms;
el sear >> d >> h >> m >> s >> ms;
}
voi d CTi mer : : St r i ng2Ti me( CSt r i ng t m){
CTi mer t out ;CSt r i ng t emp = t m;LPTSTR num;i nt ni nt ;i nt p;
i nt l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ T#’ ’ ) ;i f ( p ! = - 1)
t emp = t emp. Ri ght ( l engt h- p- 2) ;
l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ d_’ ’ ) ;i f ( p ! = - 1){
CSt r i ng n = t emp. Lef t ( p) ;num = n. Get Buf f er ( 5) ;ni nt = at oi ( num) ;t hi s- >d = ni nt ;n. Rel easeBuf f er ( ) ;t emp = t emp. Ri ght ( l engt h- p- 2) ;
}
l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ h_’ ’ ) ;i f ( p ! = - 1){
CSt r i ng n = t emp. Lef t ( p) ;num = n. Get Buf f er ( 5) ;ni nt = at oi ( num) ;t hi s- >h = ni nt ;n. Rel easeBuf f er ( ) ;t emp = t emp. Ri ght ( l engt h- p- 2) ;
}l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ m_’ ’ ) ;i f ( p ! = - 1){
CSt r i ng n = t emp. Lef t ( p) ;num = n. Get Buf f er ( 5) ;ni nt = at oi ( num) ;t hi s- >m = ni nt ;n. Rel easeBuf f er ( ) ;
253
t emp = t emp. Ri ght ( l engt h- p- 2) ;}l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ s_’ ’ ) ;i f ( p ! = - 1){
CSt r i ng n = t emp. Lef t ( p) ;num = n. Get Buf f er ( 5) ;ni nt = at oi ( num) ;t hi s- >s = ni nt ;n. Rel easeBuf f er ( ) ;t emp = t emp. Ri ght ( l engt h- p- 2) ;
}l engt h = t emp. Get Lengt h( ) ;p = t emp. Fi nd( ’ ’ ms’ ’ ) ;i f ( p ! = - 1){
CSt r i ng n = t emp. Lef t ( p) ;num = n. Get Buf f er ( 5) ;ni nt = at oi ( num) ;t hi s- >ms = ni nt ;n. Rel easeBuf f er ( ) ;
}
}
classCTimeDlg
File : TimeDlg.h#i f ! def i ned( AFX_TI MEDLG_H__15594500_07C5_11D3_8FB1_F1D848B6483A__I NCLUDED_)#def i ne AFX_TI MEDLG_H__15594500_07C5_11D3_8FB1_F1D848B6483A__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / Ti meDl g. h : header f i l e/ /
cl ass CTi meDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CTi meDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CTi meDl g)enum { I DD = I DD_TI ME_DLG } ;i nt m_hour s;i nt m_msec;i nt m_mi n;i nt m_sec;i nt m_days;/ / } } AFX_DATA
/ / Over r i des
254
/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CTi meDl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CTi meDl g)
/ / NOTE: t he Cl assWi zar d wi l l add member f unct i ons her e/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_TI MEDLG_H__15594500_07C5_11D3_8FB1_F1D848B6483A__I NCLUDED_)
File : TimeDlg.cpp/ / Ti meDl g. cpp : i mpl ement at i on f i l e/ /
#i ncl ude ’ ’ st daf x. h’ ’#i ncl ude ’ ’ SFC. h’ ’#i ncl ude ’ ’ Ti meDl g. h’ ’
#i f def _DEBUG#def i ne new DEBUG_NEW#undef THI S_FI LEst at i c char THI S_FI LE[ ] = __FI LE__;#endi f
File : TransDlg.h#i f ! def i ned( AFX_TRANSDLG_H__12F657A0_570A_11D3_8FB1_E7E66922090D__I NCLUDED_)#def i ne AFX_TRANSDLG_H__12F657A0_570A_11D3_8FB1_E7E66922090D__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000/ / Tr ansDl g. h : header f i l e/ /
cl ass CTr ansDl g : publ i c CDi al og{/ / Const r uct i onpubl i c:
CTr ansDl g( CWnd* pPar ent = NULL) ; / / st andar d const r uct or
/ / Di al og Dat a/ / { { AFX_DATA( CTr ansDl g)enum { I DD = I DD_TRANS_DI ALOG } ;CSt r i ng m_condi t i on;/ / } } AFX_DATA
/ / Over r i des/ / Cl assWi zar d gener at ed vi r t ual f unct i on over r i des/ / { { AFX_VI RTUAL( CTr ansDl g)pr ot ect ed:vi r t ual voi d DoDat aExchange( CDat aExchange* pDX) ; / / DDX/ DDV suppor t/ / } } AFX_VI RTUAL
/ / I mpl ement at i onpr ot ect ed:
/ / Gener at ed message map f unct i ons/ / { { AFX_MSG( CTr ansDl g)
/ / NOTE: t he Cl assWi zar d wi l l add member f unct i ons her e
256
/ / } } AFX_MSGDECLARE_MESSAGE_MAP( )
} ;
/ / { { AFX_I NSERT_LOCATI ON} }/ / Mi cr osof t Devel oper St udi o wi l l i nser t addi t i onal decl ar at i ons i mmedi at el y bef o-r e t he pr evi ous l i ne.
#endi f / / ! def i ned( AFX_TRANSDLG_H__12F657A0_570A_11D3_8FB1_E7E66922090D__I NCLUDED_)
File : TransDlg.cpp/ / Tr ansDl g. cpp : i mpl ement at i on f i l e/ /
#i f ! def i ned( AFX_TRANSOBJ_H__AE826183_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_)#def i ne AFX_TRANSOBJ_H__AE826183_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
#i ncl ude ’ ’ Dr awObj . h’ ’
c l ass CTr ansObj : publ i c CDr awObj{
DECLARE_SERI AL ( CTr ansObj )
publ i c:/ / member f unct i onvi r t ual BOOL Check( i nt & war , i nt & er r ) ;vi r t ual CPoi nt Get Handl e( i nt count , CDr awObj * * pAr c) ;vi r t ual CSt r i ng Text ual For m( ) ;vi r t ual i nt maxCount ( ) ;vi r t ual voi d OnEdi t Pr oper t y( CSFCVi ew * pVi ew) ;vi r t ual voi d Expand( bool det ai l ed) ;vi r t ual voi d Dr awDet ai l s( CSFCVi ew * pVi ew, CDC * pDC) ;vi r t ual voi d Ser i al i ze( CAr chi ve & ar ) ;vi r t ual voi d Sel ect I t em( CSFCVi ew * pVi ew) ;vi r t ual voi d Dr awI t em( CSFCVi ew * pVi ew, CDC * pDC) ;CTr ansObj ( CPoi nt poi nt ) ;vi r t ual ~CTr ansObj ( ) ;
/ / member var i abl esCSt r i ng m_condi t i on;i nt m_number ;
pr ot ect ed:CTr ansObj ( ) ;f r i end cl ass CTr ansTool ;
} ;
#endi f / / ! def i ned( AFX_TRANSOBJ_H__AE826183_F410_11D2_8FB1_CA3566BD6517__I NCLUDED_)
/ / i mpl ement a l a cl asse ser i al i zzabi l eI MPLEMENT_SERI AL ( CTr ansObj , CDr awObj , 0)
/ / cost r ut t or e speci f i coCTr ansObj : : CTr ansObj ( CPoi nt poi nt ) : CDr awObj ( Tr Obj ){
m_r ect . l ef t = poi nt . x* m_gr i d- m_di m* 2;m_r ect . t op = poi nt . y* m_gr i d- m_di m/ 2;m_r ect . r i ght = poi nt . x* m_gr i d+m_di m* 2;m_r ect . bot t om = poi nt . y* m_gr i d+m_di m/ 2;
m_posi t i on = poi nt ;
m_condi t i on = ’ ’ TRUE’ ’ ;
m_nLower Li nk = 1;m_nUpper Li nk = 1;
}
/ / cost r ut t or e st andar d per l a ser i al i zzazi oneCTr ansObj : : CTr ansObj ( ) : CDr awObj ( Tr Obj ){
}
CTr ansObj : : ~CTr ansObj ( ){
}
/ / di segna l a t r ansi zi onevoi d CTr ansObj : : Dr awI t em( CSFCVi ew * pVi ew, CDC * pDC){
CPoi nt cent r ( m_posi t i on. x* m_gr i d, m_posi t i on. y* m_gr i d) ;
CPen MyPen;CPen * pOr i gi nal Pen;BOOL changed = FALSE;BOOL cor r ect ;
i f ( pVi ew- >bCheck){
i nt t emp1, t emp2;cor r ect = Check( t emp1, t emp2) ;
}
i f ( ! pDC- >I sPr i nt i ng( ) ){
/ / se l ’ ogget t o \ UNI CODE{ 0xe8} sel ezi onat o cambi a col or ei f ( pVi ew- >m_sel ect i on. Fi nd( t hi s) ){
/ / di segnopDC- >MoveTo( cent r . x- m_di m/ 3, cent r . y) ;pDC- >Li neTo( cent r . x+m_di m/ 3, cent r . y) ;pDC- >MoveTo( cent r . x, cent r . y- m_di m/ 2) ;pDC- >Li neTo( cent r . x, cent r . y+m_di m/ 2) ;
/ / numer o del l a t r ansi zi oneCRect r ect ( m_r ect . l ef t , m_r ect . t op, cent r . x- m_di m/ 3, m_r ect . bot t om) ;CSt r i ng num;num. For mat ( ’ ’ T%i ’ ’ , m_number +100* n_SFC) ;
pDC- >Dr awText ( m_condi t i on, condi t i onRect , DT_SI NGLELI NE | DT_VCENTER) ;pDC- >Sel ect Obj ect ( pOl dFont ) ;
}
/ / f unzi one per r i or gani zzar e i l r et t angol o i nval i dant e i n pr esenza di/ / v i sual i zzazi one det t agl i at avoi d CTr ansObj : : Expand( bool det ai l ed){
i f ( det ai l ed)m_r ect . r i ght += 2* m_di m;
el sem_r ect . r i ght - = 2* m_di m;
}
261
/ / v i sual i zza l a f i nest r a di pr opr i et \ UNI CODE{ 0xe0} del l a t r ansi zi onevoi d CTr ansObj : : OnEdi t Pr oper t y( CSFCVi ew * pVi ew){
CTr ansDl g dl g;
dl g. m_condi t i on = m_condi t i on;
i f ( dl g. DoModal ( ) == I DOK)/ / r et r i eve t he di al og dat am_condi t i on = dl g. m_condi t i on;
}
/ / r est i t ui sce i l numer o pi \ UNI CODE{ 0xf 9} al t o t r a l e t r ansi zi oni +1i nt CTr ansObj : : maxCount ( ){
i nt max = 0;POSI TI ON pos = pObj Li st - >Get HeadPosi t i on( ) ;CDr awObj * pObj ;whi l e ( pos ! = NULL){
pObj = pObj Li st - >Get Next ( pos) ;i f ( pObj - >m_Type == Tr Obj ){
#i f ! def i ned( AFX_TRANSTOOL_H__A5936FC0_EC44_11D2_B1B8_818EF9F33F37__I NCLUDED_)#def i ne AFX_TRANSTOOL_H__A5936FC0_EC44_11D2_B1B8_818EF9F33F37__I NCLUDED_
#i f _MSC_VER >= 1000#pr agma once#endi f / / _MSC_VER >= 1000
cl ass CTr ansTool{publ i c:
/ / member f unct i onsst at i c voi d OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags, const CPoi nt & poi nt ) ;st at i c voi d OnNewObj ( CSFCVi ew * pVi ew, CPoi nt poi nt ) ;st at i c voi d OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;CTr ansTool ( ) ;vi r t ual ~CTr ansTool ( ) ;
st at i c voi d OnLBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ) ;} ;
#endi f / / ! def i ned( AFX_TRANSTOOL_H__A5936FC0_EC44_11D2_B1B8_818EF9F33F37__I NCLUDED_)
voi d CTr ansTool : : OnLBut t onDown( CSFCVi ew* pVi ew, UI NT nFl ags, CPoi nt poi nt ){
i f ( ! pVi ew- >m_pt Li nk. I sEmpt y( ) ){/ / i nser i sce una t r ansi zi one che sar \ UNI CODE{ 0xe0} l egat a ad al t r o ogget t o
CDr awObj * pLi nk;CDr awObj * pObj = pObj Li st - >Get Tai l ( ) ;
i nt n1_l i nk;/ / val ut a i l l i nk super i or e ed event ual ment e aggi unge l ’ ar copLi nk = pObj - >Eval uat eUpper Li nk( pVi ew, &n1_l i nk, 0) ;i f ( pLi nk)
i f ( ( pLi nk- >m_Type == PhObj ) | | ( pLi nk- >m_Type == SELECT) | |( pLi nk- >m_Type == SYNCRO) )
{CAr cObj * pAr c;pAr c = CAr cTool : : OnNewAr c( pLi nk, pObj , n1_l i nk, 0) ;pVi ew- >I nval Ar c( pAr c, - 1) ;
}/ / val ut a i l l i nk i nf er i or e ed event ual ment e aggi unge l ’ ar copLi nk = pObj - >Eval uat eLower Li nk( pVi ew, &n1_l i nk, 0) ;i f ( pLi nk)
i f ( ( pLi nk- >m_Type == PhObj ) | | ( pLi nk- >m_Type == PARALLEL) | |( pLi nk- >m_Type == CONVERGENCE) )
{CAr cObj * pAr c;pAr c = CAr cTool : : OnNewAr c( pObj , pLi nk, 0, n1_l i nk) ;pVi ew- >I nval Ar c( pAr c, - 1) ;
}}
OnNewObj ( pVi ew, poi nt ) ;}
voi d CTr ansTool : : OnRBut t onDown( CSFCVi ew * pVi ew, UI NT nFl ags, CPoi nt poi nt ){
CDr awObj * pObj ;i f ( pVi ew- >m_pl aci ng){
/ / se st a pi azzando una t r ansi zi one l a cancel l a e passa/ / al l o st r ument o di sel ezi onei f ( ! pObj Li st - >I sEmpt y( ) ) ;{
pObj = pObj Li st - >Get Tai l ( ) ;pObj - >Remove( ) ;pObj Li st - >RemoveTai l ( ) ;m_Obj Tool = sel ect i on;pVi ew- >I nval i dat e( ) ;pVi ew- >m_pl aci ng = FALSE;pVi ew- >m_pt Li nk. RemoveAl l ( ) ;
}}
}
/ / i nser i sce un nuovo ogget t o t r ansi zi onevoi d CTr ansTool : : OnNewObj ( CSFCVi ew * pVi ew, CPoi nt poi nt ){
CPoi nt l ocal = poi nt ;pVi ew- >Cl i ent ToDoc( l ocal ) ;
pObj Li st - >AddTai l ( NewObj ) ;pVi ew- >I nval Obj ( NewObj ) ;
}
voi d CTr ansTool : : OnMouseMove( CSFCVi ew * pVi ew, UI NT nFl ags,const CPoi nt & poi nt )
{CPoi nt l ocal = poi nt ;CDr awObj * pObj ;CDr awObj * pLi nk;
CDr awObj * t emp;
i f ( pVi ew- >m_pl aci ng){
pObj = pObj Li st - >Get Tai l ( ) ;pVi ew- >Cl i ent ToDoc( l ocal ) ;
CPoi nt near Poi nt = pVi ew- >Near est OnGr i d( l ocal ) ;CPoi nt cent er = pObj - >m_posi t i on;i f ( cent er ! = near Poi nt ){
pVi ew- >m_pt Li nk. RemoveAl l ( ) ;pVi ew- >I nval Obj ( pObj ) ;pObj - >MoveTo( near Poi nt ) ;pVi ew- >I nval Obj ( pObj ) ;
i nt n1_l i nk;
pLi nk = pObj - >Eval uat eUpper Li nk( pVi ew, &n1_l i nk, 0) ;i f ( pLi nk)
i f ( ( pLi nk- >m_Type == PhObj ) | | ( pLi nk- >m_Type == SELECT) | |( pLi nk- >m_Type == SYNCRO) ){
pVi ew- >m_pt Li nk. AddTai l ( pObj - >Get Handl e( 20, &t emp) ) ;MessageBeep( 0) ;
}pLi nk = pObj - >Eval uat eLower Li nk( pVi ew, &n1_l i nk, 0) ;i f ( pLi nk)
i f ( ( pLi nk- >m_Type == PhObj ) | | ( pLi nk- >m_Type == PARALLEL) | |( pLi nk- >m_Type == CONVERGENCE) ){
pVi ew- >m_pt Li nk. AddTai l ( pObj - >Get Handl e( 30, &t emp) ) ;MessageBeep( 0) ;
}
}}
}
File : SFC.rc/ / { { NO_DEPENDENCI ES} }/ / Mi cr osof t Devel oper St udi o gener at ed i ncl ude f i l e./ / Used by SFC. r c/ /
268
#def i ne ER_UPLNKNOTCOMP 0x1#def i ne WN_UPLNKFLOAT 0x1#def i ne ER_DWLNKNOTCOMP 0x2#def i ne WN_DWLNKFLOAT 0x2#def i ne I D_PRI NTER_SETUP 3#def i ne ER_AMBI GFLOW 0x4#def i ne ER_UPFLOWERROR 0x8#def i ne ER_DWFLOWERROR 0x10#def i ne ER_I NCOMPLI NK 0x20#def i ne ER_OBJFLOATI NG 0x40#def i ne I DD_ABOUTBOX 100#def i ne I DD_MULTI _DLG 102#def i ne I DD_TABBAR 103#def i ne I DD_ACTI ON_DI ALOG 106#def i ne I DD_TI ME_DLG 107#def i ne I DR_MAI NFRAME 128#def i ne I DR_SFCTYPE 129#def i ne I DD_TRANS_DI ALOG 134#def i ne I DD_DI ALOGBAR 135#def i ne I DD_EDI T_SFC_NAME 136#def i ne I DD_PAGESI ZE_DI ALOG 137#def i ne I DD_PAGE_SPLI T 138#def i ne I DI _I CON1 139#def i ne I DD_OUTPUT_DLG 139#def i ne I DC_TAB 1000#def i ne I DC_ACTI ON_QUALF 1001#def i ne I DC_EDI T_TI ME_DUR 1002#def i ne I DC_EDI T_ACTI ON_NAME 1003#def i ne I DC_EDI T_STEP_NUM 1006#def i ne I DC_N_LI NKS 1010#def i ne I DC_SPACI NG 1011#def i ne I DC_SPI N1 1012#def i ne I DC_SPI N2 1013#def i ne I DC_SPEC_TI ME 1013#def i ne I DC_I NI TI AL 1015#def i ne I DC_TI ME_DAYS 1016#def i ne I DC_TI ME_MI N 1017#def i ne I DC_TI ME_HOURS 1018#def i ne I DC_TI ME_SEC 1019#def i ne I DC_TI ME_MI LSEC 1020#def i ne I DC_TI ME_STRI NG 1020#def i ne I DC_CONDI TI ON_EDI T 1021#def i ne I DC_EDI T_SFC_NAME 1022#def i ne I DC_EDI T_WI DTH 1023#def i ne I DC_EDI T_HEI GHT 1024#def i ne I DC_SCALE_SLI DER 1024#def i ne I DC_DOCSI ZE 1025#def i ne I DC_PAGESI ZE 1026#def i ne I DC_SCALE 1027#def i ne I DC_SPLI T_PREVI EW 1028#def i ne I DC_NUM_PAGES 1029#def i ne I DC_PROGRESS1 1030#def i ne I DC_RESULTS 1031#def i ne I DC_AGAI N_BUTTON 1032#def i ne I DC_AUTO_SI ZE 1033#def i ne I D_PHASE0_BUTTON 32771#def i ne I D_PHASE_BUTTON 32772#def i ne I D_TRANS_BUTTON 32773#def i ne I D_ARC_BUTTON 32775#def i ne I D_SEL_BUTTON 32776#def i ne I D_MULTI _2BUTTON 32777#def i ne I D_MULTI _4BUTTON 32778#def i ne I D_MULTI _1BUTTON 32780#def i ne I D_MULTI _3BUTTON 32781#def i ne I D_CANCEL 32782
269
#def i ne I DM_ZOOM_41 32783#def i ne I DM_ZOOM_31 32784#def i ne I DM_ZOOM_21 32785#def i ne I DM_ZOOM_11 32786#def i ne I DM_ZOOM_12 32787#def i ne I DM_ZOOM_13 32788#def i ne I DM_ZOOM_14 32789#def i ne I DM_SFC_ADDSFC 32790#def i ne I D_PROJ_OPEN 32791#def i ne I D_EXPAND_SWI TCH 32792#def i ne I D_SCALE_BUTTON 32793#def i ne I D_RFRSH_BUTTON 32796#def i ne I D_BUTTON23 32797#def i ne I D_PROJ_SAVE 32798#def i ne I D_SAVE_PROJ_AS 32799#def i ne I D_MLF_CREATE 32800#def i ne I DM_REMOVESFC 32801#def i ne I DM_EDI T_SFC_NAME 32802#def i ne I D_SETDOCSI ZE_BUTTON 32803#def i ne I D_PAGE_SETUP 32804#def i ne I D_BUTTON32805 32805#def i ne I D_CHECK_BUTTON 32806#def i ne I D_EXPORT_BUTTON 32807#def i ne I DS_STRI NG57638 57638#def i ne I DS_CONFI RM 61446
/ / Next def aul t val ues f or new obj ect s/ /#i f def APSTUDI O_I NVOKED#i f ndef APSTUDI O_READONLY_SYMBOLS#def i ne _APS_3D_CONTROLS 1#def i ne _APS_NEXT_RESOURCE_VALUE 140#def i ne _APS_NEXT_COMMAND_VALUE 32810#def i ne _APS_NEXT_CONTROL_VALUE 1034#def i ne _APS_NEXT_SYMED_VALUE 101#endi f#endi f
270
Bibliografia
[1] PasqualeChiacchio, PLC eautomazione industriale, Mc Graw Hill (1996)
[2] Catalogo Prodotti, ‘‘Sistemi di Automazione Allen Bradley’’ , Rockwell