1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 #ifndef _Network_h
16 #define _Network_h
17 
18 #include "enums.h"
19 #include "Base.h"
20 #include "List.h"
21 #include "NodeList.h"
22 #include "Parse.h"
23 #include "SymbolManager.h"
24 #include "PacketIF.h"
25 #include "WorkSpaceInfo.h"
26 
27 typedef long CPNodeStatus;	// Also defined in ControlPanel.h
28 
29 //
30 // Class name definition:
31 //
32 #define ClassNetwork	"Network"
33 
34 
35 //
36 // Defines the default output remapping mode.
37 // When FALSE, outputs are not to be remapped by the executive.
38 // This is however only advisor, it is up to the DrivenInteractorNodes and
39 // their derived classes to read their Network's remap mode an use it.
40 //
41 #define DEFAULT_REMAP_INTERACTOR_MODE	FALSE
42 
43 //
44 // Referenced classes:
45 //
46 
47 class Dictionary;
48 class EditorWindow;
49 class GetSetConversionDialog;
50 class ImageWindow;
51 class ControlPanel;
52 class CommandScope;
53 class Command;
54 class Node;
55 class StandIn;
56 class SaveAsDialog;
57 class Dialog;
58 class SequencerNode;
59 class DeferrableAction;
60 class EditorWorkSpace;
61 class TransmitterNode;
62 
63 class MacroDefinition;
64 class MacroParameterNode;
65 class ParameterDefinition;
66 class PanelGroupManager;
67 class PanelAccessManager;
68 class DXApplication;
69 class CascadeMenu;
70 class Decorator;
71 class UniqueNameNode;
72 
73 #define FOR_EACH_NETWORK_NODE(network, node, iterator) \
74  for (iterator.setList(network->nodeList) ; (node = (Node*)iterator.getNext()) ; )
75 #define FOR_EACH_NETWORK_PANEL(network, cp, iterator) \
76  for (iterator.setList(network->panelList) ; \
77 	(cp = (ControlPanel*)iterator.getNext()) ; )
78 #define FOR_EACH_NETWORK_DECORATOR(network, decor, iterator) \
79  for (iterator.setList(network->decoratorList); (decor = (Decorator*)iterator.getNext()); )
80 
81 
82 //
83 // Network class definition:
84 //
85 class Network : public Base
86 {
87     friend class DXApplication;	// For the constructor
88 
89   private:
90     //
91     // Methods for extern "C" functions reference by yacc.
92     //
93     void parseComment(char *comment);
94     void parseFunctionID(char *name);
95     void parseArgument(char *name, const boolean isVarname);
96     void parseLValue(char *name);
97     void parseRValue(char *name);
98     void parseStringAttribute(char *name, char *value);
99     void parseIntAttribute(char *name, int value);
100     void parseEndOfMacroDefinition();
101 
102     //
103     // Parse all .net file comments.
104     //
105     void parseVersionComment(const char* comment, boolean netfile);
106     boolean netParseComments(const char* comment, const char *file,
107 							int lineno);
108     void netParseMacroComment(const char* comment);
109     void netParseMODULEComment(const char* comment);
110     void netParseVersionComment(const char* comment);
111     void netParseCATEGORYComment(const char* comment);
112     void netParseDESCRIPTIONComment(const char* comment);
113     void netParseCommentComment(const char* comment);
114     void netParseNodeComment(const char* comment);
115 
116     //
117     // Parse all .cfg file comments.
118     //
119     boolean cfgParseComments(const char* comment, const char *file,
120 							int lineno);
121     void cfgParsePanelComment(const char* comment);
122     void cfgParseInteractorComment(const char* comment);
123     void cfgParseNodeComment(const char* comment);
124     void cfgParseVersionComment(const char* comment);
125     ControlPanel *selectionOwner;
126 
127 
128     //
129     // Parsing routines used by yacc.
130     //
131     friend void ParseComment(char* comment);
132     friend void ParseFunctionID(char* name);
133     friend void ParseArgument(char* name, const boolean isVarname);
134     friend void ParseLValue(char* name);
135     friend void ParseRValue(char* name);
136     friend void ParseIntAttribute(char* name, int value);
137     friend void ParseStringAttribute(char* name, char* value);
138     friend void ParseEndOfMacroDefinition();
139     friend void yyerror(char *, ...);
140 
141     int visitNodes(Node *n);
142     boolean markAndCheckForCycle(Node *srcNode, Node *dstNode);
143 
144 
145     //
146     // Static methods used by the DeferrableAction
147     // class member below.
148     //
149     static void AddNodeWork(void *staticData, void *requestData);
150     static void RemoveNodeWork(void *staticData, void *requestData);
151 
152     //
153     // Static method used by the sendNetwork DeferrableAction
154     // class member below.
155     //
156     static void SendNetwork(void *staticData, void *requestData);
157 
158     //
159     // CommandInterfaces that use these two commands must arrange to set
160     // the instance number of the desired panel in the local data using
161     // UIComponent::setLocalData().  Further, these are never de/activated()
162     // and are created activated.  These are set up this way, because
163     // anything that allows opening specific panels will have to be dynamic
164     // (given an editor and the fact that the indices are kept in the
165     // CommandInterface).  The CommandInterfaces that use these are created
166     // in this->fillPanelCascade().
167     //
168     Command*		openPanelByInstanceCmd;
169     Command*		openPanelGroupByIndexCmd;
170 
171     //
172     // Used by prepareFor/completeNewNetwork() and addNode() to defer
173     // notifying the editor of the new nodes.  Instead we notify the editor
174     // after the network is complete.
175     //
176     boolean             readingNetwork;
177 
178     //
179     // Add the given panel this network and if the instance number is 0
180     // then allocate a new instance number for the panel.
181     //
182     boolean addPanel(ControlPanel *p, int instance = 0);
183 
184     //
185     // Check version numbers using rules taken from ParseVersionComment
186     // If there is a problem post on Info Message
187     //
188     boolean versionMismatchQuery (boolean netfile, const char *file);
189 
190     //
191     // If the net came from a file and the file was encrypted,
192     // then this is set to TRUE.
193     //
194     boolean netFileWasEncoded;
195 
196     static Decorator* lastObjectParsed;
197     // Print decorator comments in the .net file.
198     static void SetOwner(void*);
199     static void DeleteSelections(void*);
200     static void Select(void*);
201     virtual boolean parseDecoratorComment (const char *comment,
202                                 const char *filename, int lineno);
203 
204     //
205     // This is a helper function for optimizeNodeOutputCacheability() that
206     // returns a list of Nodes that are connected to the given output of the
207     // given node.  This would be trivial, except for Transmitters and
208     // Receivers, In which case we need to traverse all Receivers for a
209     // given Transmitter and all output arcs for each receiver.
210     // If destList is given, then we append the Nodes to that list,
211     // otherwise we allocate one internally.  In either case, we return a
212     // list.  In the latter case, the user should delete the returned list.
213     //
214     static List *GetDestinationNodes(Node *src, int output_index,
215 			List *destList, boolean rcvrsOk = FALSE);
216 
217     //
218     // Do a recursive depth-first search of this network for macro nodes.
219     // and append their MacroDefinitions to the given list.  The list will
220     // come back in depth-first order and will NOT contain duplicates.
221     // This has the side effect of loading the network bodies for all the
222     // returned MacroDefinitions.
223     //
224     void getReferencedMacros(List *macros, List *visted = NULL);
225 
226 public:
227     class ParseState {
228       public:
229 	//
230 	// This is state that is defined over a whole .net or .cfg file
231 	//
232 	static Network 		*network;
233 	static char		*parse_file;
234 	static boolean		error_occurred;
235 	static boolean 		stop_parsing;
236 	static boolean 		issued_version_error;
237 	static boolean 		ignoreUndefinedModules;
238 	static Dictionary	*undefined_modules;
239 	static Dictionary	*redefined_modules;
240 	static int		parse_mode;
241 	static boolean 		main_macro_parsed;
242 
243 	ParseState();
244 	~ParseState();
245 	void initializeForParse(Network *n, int mode, const char *filename);
246 	void cleanupAfterParse();
247 
248 	//
249 	// This is state that is set for parsing a macro within a .net file
250 	//
251 	int	parse_state;
252 
253 #if WORKSPACE_PAGES
254 	//
255 	// What did we just parse?  Was it a node or a decorator?  There are
256 	// stateful comments which could apply to either and we must know
257 	// wether to parseDecoratorComment or node->netParseComment.
258 	// group comments belong to either node or decorator.
259 	//
260 	int     parse_sub_state;
261 #endif
262 
263 	Node	*node;
264 	int	input_index;
265 	int	output_index;
266 	boolean	node_error_occurred;
267 	ControlPanel *control_panel;
268 
269     } parseState;
270 
271 private:
272 
273     //
274     // Keep track if whether or not the .net had a Get or a Set in it.
275     //
276     boolean fileHadGetOrSetNodes;	// Set during parse of .net file
277 
278     //
279     // See fixupTransmitter() below for comment.
280     //
281     static List* RenameTransmitterList;
282 
283 #if WORKSPACE_PAGES
284     Dictionary* groupManagers;
285 #endif
286 
287   protected:
288     friend class StandIn;
289     friend class EditorWindow;
290     friend class GetSetConversionDialog; // for getReferencedMacros
291 
292     //
293     // Protected member data:
294     //
295     EditorWindow*	editor;		// editor for this network
296     List		imageList;	// image window list
297     List		panelList;	// control panel list
298     NodeList		nodeList;	// network node list
299 
300     List		decoratorList;  // LabelDecorators in the vpe
301 #if 00
302     List                pickList;       // List of pick nodes
303     List                transmitterList;// Contains transmitters so that
304 					// receivers can find them.
305     List                receiverList;   // Contains receivers without
306 					// transmitters so that
307 					// new transmitters can find them.
308     List		probeList;	// list of all probe nodes.
309 #endif
310 
311     char 		*description;
312     char 		*comment;
313     Symbol		category;
314     Symbol		name;
315     char 		*prefix;
316     boolean		remapInteractorOutputs;
317 
318     DeferrableAction	*deferrableRemoveNode;
319     DeferrableAction	*deferrableAddNode;
320     DeferrableAction    *deferrableSendNetwork;
321 
322 
323     struct {
324 	short		major;
325 	short		minor;
326 	short		micro;
327     } 			netVersion;
328     struct {
329 	short		major;
330 	short		minor;
331 	short		micro;
332     } 			dxVersion;
333 
334 
335     CommandScope*	commandScope;
336     Command*		openAllPanelsCmd;
337     Command*		closeAllPanelsCmd;
338     Command*		newCmd;
339     Command*		saveAsCmd;
340     Command*		saveCmd;
341     Command*		saveCfgCmd;
342     Command*		openCfgCmd;
343     Command*		setNameCmd;
344     Command*		helpOnNetworkCmd;
345 
346     boolean		parse(FILE *f);
347     boolean		dirty;
348     boolean		fileDirty;
349     char*               fileName;
350 
351     boolean             macro;
352     MacroDefinition     *definition;
353     boolean		deleting;		// True during destructor.
354 
355     SaveAsDialog	*saveAsDialog;
356     Dialog		*saveCfgDialog;
357     Dialog		*openCfgDialog;
358     Dialog		*setNameDialog;
359     Dialog		*setCommentDialog;
360     Dialog		*helpOnNetworkDialog;
361 
362     //
363     // Parse any network specific info out of the .cfg comments.
364     //
365     boolean cfgParseComment(const char *name, const char *file, int lineno);
366 
367     //
368     // Used to allocate uniq ids for control panels in this network.
369     //
370     int 	lastPanelInstanceNumber;
371 
372     PanelGroupManager* panelGroupManager;
373     PanelAccessManager* panelAccessManager;
374 
375     //
376     // This will reset the image count for isLastImage();
377     int  imageCount;
378     void resetImageCount();
379 
380     //
381     // Deletes a given panel from the panel list.
382     // Should you be using this->closeControlPanel(...).
383     //
384     boolean deletePanel(ControlPanel* panel, boolean destroyPanelsNow = FALSE);
385 
386     //
387     // Do any work that is necessary to read in a new .cfg file and/or
388     // clear the network of any .cfg information.
389     //
390     void clearCfgInformation(boolean destroyPanelsNow = FALSE);
391 
392     //
393     // The work space grid to be used by the editor.
394     //
395     WorkSpaceInfo	workSpaceInfo;
396 
397 
398     //
399     // Ask various windows to reset their titles.
400     //
401     void resetWindowTitles();
402 
403 
404 
405     //
406     // Do whatever is necessary to speed up the process of reading in a
407     // new network.  This includes letting the EditorWindow know by calling
408     // editor->prepareFor/completeNewNetwork().
409     //
410     void prepareForNewNetwork();
411     void completeNewNetwork();
412 
413 #ifdef  DXUI_DEVKIT
414     //
415     // Print the visual program as a .c file that uses libDX calls.
416     // An error message is printed if there was an error.
417     //
418     boolean printAsCCode(FILE *f);
419 #endif // DXUI_DEVKIT
420 
421     //
422     // Print comments and 'include' statements for the macros that are
423     // referenced in this network.  If nested is TRUE, then we don't print
424     // the 'include' statements.  Return TRUE on sucess or FALSE on failure.
425     // nested and processedMacros args are only really intended to be
426     // used in the recursive calls (i.e. not by generic users).
427     //
428     virtual boolean printMacroReferences(FILE *f, boolean inline_define,
429                         PacketIFCallback echoCallback, void *echoClientData);
430 
431     //
432     // Constructor:
433     //  THIS CONSTRUCTOR SHOULD NEVER BE CALLED FROM ANYWHERE BUT
434     //  DXApplication::newNetwork OR A SUBCLASS OF NETWORK.  ANY
435     //  SUBCLASSES CONSTRUCTOR SHOULD ONLY BE CALLED FROM A VIRTUAL
436     //  REPLACEMENT OF DXApplication::newNetwork.
437     //
438     Network();
439 
440 
441     //
442     // For editing operations which automatically chop arcs and replace
443     // them with transmitters/receivers.
444     //
445     boolean	chopInputArk(Node*, int, Dictionary*, Dictionary*);
446 
447   public:
448 
449     SequencerNode* sequencer;	// FIXME! does this need to be public.
450 
451     //
452     // Destructor:
453     //
454     ~Network();
455 
456     //
457     // Adds a given image window to the image window list.
458     // Deletes a given image window from the image window list.
459     //
460     boolean addImage(ImageWindow* image);
getImageList()461     List   *getImageList() { return &this->imageList; }
getImageCount()462     int		getImageCount() { return this->imageList.getSize(); }
463     boolean removeImage(ImageWindow* image);
464 
465     //
466     // Posts the sequencer
467     void    postSequencer();
468 
469     void    setRemapInteractorOutputMode(boolean val = TRUE);
isRemapInteractorOutputMode()470     boolean isRemapInteractorOutputMode()
471 		{ return this->remapInteractorOutputs; }
472 
473 
474 #if 00
475     // Maintain the Transmitter and Receiver lists.
476     // The transmitter list contains all transmitters, and the receiver
477     // list contains only "transmitter-less" receivers.
478     boolean addTransmitter(Node *n);
479     boolean removeTransmitter(Node *n);
480     Node   *getTransmitter(int i);
481     int     getTransmitterCount();
482 
483     boolean addReceiver(Node *n);
484     boolean removeReceiver(Node *n);
485     Node   *getReceiver(int i);
486     int     getReceiverCount();
487 #endif
488 
489     //
490     // Probe management:
491     //
492 #if 00
493     boolean addProbe(Node*);
494     boolean deleteProbe(Node*);
495     boolean changeProbe(Node*);
496     int	    getProbeListSize();
497     List    *getProbeList();
498 #endif
499 
500     //
501     // Pick management:
502     //
503 #if 00
504     boolean addPick(Node*);
505     boolean deletePick(Node*);
506     boolean changePick(Node*);
507     int	    getPickListSize();
508     List    *getPickList();
509 #endif
510 
511     //
512     // Find a panel by index (indexed from 1).
513     //
getPanelByIndex(int index)514     ControlPanel *getPanelByIndex(int index)
515 		{ ASSERT(index > 0);
516 		  return (ControlPanel*) this->panelList.getElement(index); }
getPanelCount()517     int getPanelCount() { return  this->panelList.getSize(); }
518     ControlPanel *getPanelByInstance(int instance);
519     List *getNonEmptyPanels();
520 
521     //
522     // Close the given panel indicated by panelInstance.
523     // If panelInstance is 0, unmanage all panels.
524     // If the given panel(s) contain 0 interactors, then also call
525     // this->deletePanel() on the panel.
526     // If do_unmanage is true, then unmanage the control panel(s).
527     // do_unmanage should be FALSE when call from the control panel's
528     // close callback.
529     //
530     void closeControlPanel(int panelInstance, boolean do_unmanage = TRUE);
531     //
532     // Open the given panel indicated by panelInstance.
533     // If panelInstance is 0, manage all panels.
534     //
535     void openControlPanel(int panelInstance);
536     //
537     // Open the given panel group indicated by groupIndex.
538     // Group indices are 1 based.
539     //
540     void openControlPanelGroup(int groupIndex);
541 
542     //
543     // Access routines:
544     //
getEditor()545     EditorWindow* getEditor()
546     {
547 	return this->editor;
548     }
549 
getCloseAllPanelsCommand()550     Command* getCloseAllPanelsCommand()
551     {
552 	return this->closeAllPanelsCmd;
553     }
getOpenAllPanelsCommand()554     Command* getOpenAllPanelsCommand()
555     {
556 	return this->openAllPanelsCmd;
557     }
getNewCommand()558     Command* getNewCommand()
559     {
560 	return this->newCmd;
561     }
getSaveAsCommand()562     Command* getSaveAsCommand()
563     {
564 	return this->saveAsCmd;
565     }
getSaveCommand()566     Command* getSaveCommand()
567     {
568 	return this->saveCmd;
569     }
570 
571     //
572     // These don't really belong in Network, however their inclusion
573     // here obviates the need to include JavaNet.h in other places
574     //
getSaveWebPageCommand()575     virtual Command* getSaveWebPageCommand() { return NUL(Command*); }
getSaveAppletCommand()576     virtual Command* getSaveAppletCommand() { return NUL(Command*); }
getSaveBeanCommand()577     virtual Command* getSaveBeanCommand() { return NUL(Command*); }
578 
getSaveCfgCommand()579     Command* getSaveCfgCommand()
580     {
581 	return this->saveCfgCmd;
582     }
getOpenCfgCommand()583     Command* getOpenCfgCommand()
584     {
585 	return this->openCfgCmd;
586     }
getSetNameCommand()587     Command* getSetNameCommand()
588     {
589 	return this->setNameCmd;
590     }
getHelpOnNetworkCommand()591     Command* getHelpOnNetworkCommand()
592     {
593 	return this->helpOnNetworkCmd;
594     }
595     boolean  clear(boolean destroyPanelsNow = FALSE);
596 
597 
598     //
599     // Net file format version access functions
600     //
getDXMajorVersion()601     int	getDXMajorVersion() { return this->dxVersion.major; }
getDXMinorVersion()602     int	getDXMinorVersion() { return this->dxVersion.minor; }
getDXMicroVersion()603     int	getDXMicroVersion() { return this->dxVersion.micro; }
604     //
605     // Net file format version access functions
606     //
getNetMajorVersion()607     int	getNetMajorVersion() { return this->netVersion.major; }
getNetMinorVersion()608     int	getNetMinorVersion() { return this->netVersion.minor; }
getNetMicroVersion()609     int	getNetMicroVersion() { return this->netVersion.micro; }
getVersion(int & maj,int & min,int & mic)610     void getVersion(int &maj, int& min, int& mic)
611 			{ maj = this->netVersion.major;
612 			  min = this->netVersion.minor;
613 			  mic = this->netVersion.micro; }
614 
615     //
616     // Name and Category manipulations
617     //
618     void    setDescription(const char *description, boolean markDirty = TRUE);
619     Symbol  setCategory(const char *cat, boolean markDirty = TRUE);
620     Symbol  setName(const char *n);
621     const char *getDescriptionString();
getCategoryString()622     const char *getCategoryString()
623 		{ return theSymbolManager->getSymbolString(category); }
getCategorySymbol()624     Symbol  getCategorySymbol() { return category; }
getNameString()625     const char *getNameString()
626 		{ return theSymbolManager->getSymbolString(name); }
getNameSymbol()627     Symbol  getNameSymbol() { return name; }
628     const char *getPrefix();
getNetworkComment()629     const char *getNetworkComment() { return this->comment; }
630     virtual void setNetworkComment(const char *s);
631 
632 
633     //
634     // Printing/sending script representations of this network
635     //
636     virtual boolean printNetwork(FILE *f,
637 				PrintType dest);
638     virtual boolean printHeader(FILE *f,
639 				PrintType dest,
640 				PacketIFCallback echoCallback = NULL,
641 				void *echoClientData = NULL);
642     virtual boolean printBody(FILE *f,
643 			      PrintType dest,
644 			      PacketIFCallback echoCallback = NULL,
645 			      void *echoClientData = NULL);
646     virtual boolean printTrailer(FILE *f,
647 				 PrintType dest,
648 				 PacketIFCallback echoCallback = NULL,
649 				 void *echoClientData = NULL);
650     virtual boolean printValues(FILE *f, PrintType dest);
651     virtual boolean sendNetwork();
652     virtual boolean sendValues(boolean force = FALSE);
653 
654     //
655     // Convert a filename (with or without corresponding extensions)
656     // to a filename with the correct extension.
657     //
658     static char *FilenameToNetname(const char *filename);
659     static char *FilenameToCfgname(const char *filename);
660 
661     //
662     // Determine if the network is in a state that can be saved to disk.
663     // If so, then return TRUE, otherwise return FALSE and issue an error.
664     //
665     boolean isNetworkSavable();
666 
667     //
668     // Save the network as a file in the .net and .cfg files
669     //
670     virtual boolean saveNetwork(const char *name, boolean force = FALSE);
671 
672     boolean openCfgFile(const char *name, boolean openStartup = FALSE,
673 					  boolean send = TRUE);
674     boolean saveCfgFile(const char *name);
675 
676     //
677     // markNetwork sets the flag marked[j] (0 based) if note j
678     // is connected to node i (0 based) in the d direction where d < 0
679     // means above (to its inputs), and d > 0 means below (to its outputs),
680     // and 0 means in both directions.
681     int     connectedNodes(boolean *marked, int i, int d);
682     void    sortNetwork();
683 
684     boolean checkForCycle(Node *srcNode, Node *dstNode);
685     virtual boolean readNetwork(const char *netfile, const char *cfgfile = NULL,
686 		boolean ignoreUndefinedModules = FALSE);
687 
688     // These are called by readNetwork() and any other functions that want to
689     // READ a .net file. Returns FILE* and deals with encoded networks.
690     // The static version is provided for others to open and read .net files,
691     // but they must save and pass the wasEncoded value into
692     // CloseNetworkFILE().
693     // NOTE that encoding is done outside dxui (by dxencode).
694     //
695     static FILE* OpenNetworkFILE(const char *netfile,
696 				boolean *wasEncoded, char **errmsg = NULL);
697     FILE* openNetworkFILE(const char *netfile, char **errmsg = NULL);
698     //
699     // Close the .net file that was opened with [Oo]penNetworkFILE().
700     //
701     static void CloseNetworkFILE(FILE *f, boolean wasEncoded);
702     void closeNetworkFILE(FILE *f);
703 
704 
705     //
706     // Save the network as a file in the .net and .cfg files and any
707     // per Node files (auxiliary)
708     //
709     boolean netPrintNetwork(const char *name);
710     boolean cfgPrintNetwork(const char *name, PrintType dest = PrintFile);
setCPSelectionOwner(ControlPanel * cp)711     void setCPSelectionOwner (ControlPanel *cp) { this->selectionOwner = cp; }
getSelectionOwner()712     ControlPanel *getSelectionOwner () { return this->selectionOwner; }
713     boolean auxPrintNetwork();
714 
isDirty()715     boolean isDirty() { return this->dirty; }
716     void    setDirty();
clearDirty()717     void    clearDirty() { this->dirty = FALSE; }
718     void    setFileDirty(boolean val = TRUE) { this->fileDirty = val; }
clearFileDirty()719     void    clearFileDirty() { this->fileDirty = FALSE; }
720     //
721     // Is the network different than that on disk.  Before using this,
722     // be careful, to be sure you shouldn't be using saveToFileRequired()
723     // instead.
724     //
isFileDirty()725     boolean isFileDirty() { return this->fileDirty; }
726 
727     //
728     // Return true if the network is different from that on disk, and the
729     // application allows saving of .net and .cfg files.
730     //
731     boolean saveToFileRequired();
732 
733 
734     // Add a node to the network's node list.
735     void addNode(Node *node, EditorWorkSpace *where = NULL);
736     void deleteNode(Node *node, boolean undefer=TRUE);
737     Node *findNode(Symbol name, int instance);
738 
739     Node *findNode(const char* name, int* startpos = NULL, boolean byLabel = FALSE);
740 
741     void postSaveAsDialog(Widget parent, Command* cmd = NULL);
742     void postSaveCfgDialog(Widget parent);
743     void postOpenCfgDialog(Widget parent);
744 
745     boolean postNameDialog();
746     void editNetworkComment();
747     void postHelpOnNetworkDialog();
748 
749     //
750     // isMacro returns true if this network can be considered a macro.
751     // canBeMacro returns true if there is nothing in the net that prevents
752     // it from being a macro.
753     // makeMacro makes this network a macro if do is true, else it makes it
754     // be a "normal" net.
755     boolean isMacro();
756     boolean canBeMacro();
757     boolean makeMacro(boolean make);
758 
759     ParameterDefinition *getInputDefinition(int i);
760     ParameterDefinition *getOutputDefinition(int i);
761     int getInputCount();
762     int getOutputCount();
763 
764     boolean moveInputPosition(MacroParameterNode *n, int index);
765     boolean moveOutputPosition(MacroParameterNode *n, int index);
766 
767     void setDefinition(MacroDefinition *md);
768     MacroDefinition *getDefinition();
769 
770     //
771     // Colormap Management functions
772     //
773     void    openColormap(boolean openAll);
774 
775     Node   *getNode(const char *name, int instance);
776 
777     //
778     // Manipulate the panel instance numbers for panels in this network.
779     //
resetPanelInstanceNumber()780     void   resetPanelInstanceNumber()
781 		{ this->lastPanelInstanceNumber = 0; }
setLastPanelInstanceNumber(int last)782     void   setLastPanelInstanceNumber(int last)
783 		{  ASSERT(last >= 0);
784 		this->lastPanelInstanceNumber = last; }
getLastPanelInstanceNumber()785     int	   getLastPanelInstanceNumber()
786 		{ return this->lastPanelInstanceNumber; }
newPanelInstanceNumber()787     int	   newPanelInstanceNumber()
788 		{ return ++this->lastPanelInstanceNumber; }
789     //
790     // Allocate a new control panel that belongs to this network.
791     //
792     ControlPanel *newControlPanel(int instance = 0);
793 
getPanelAccessManager()794     PanelAccessManager* getPanelAccessManager()
795     {
796 	return this->panelAccessManager;
797     }
798 
getPanelGroupManager()799     PanelGroupManager* getPanelGroupManager()
800     {
801 	return this->panelGroupManager;
802     }
803 
getFileName()804     const char* getFileName()
805     {
806 	return this->fileName;
807     }
808 
getWorkSpaceInfo()809     WorkSpaceInfo *getWorkSpaceInfo()
810     {
811 	return &this->workSpaceInfo;
812     }
813 
814     //
815     // Returns true if the caller is the last element of the image list.
816     // It is assumed that each member of this list will determine, during
817     // Node::prepareToSendNode, will call this to see if it's the last one.
818     boolean isLastImage();
819 
820     //
821     // Given lists of old and new NodeDefinitions, redefine any nodes
822     // in the current network.
823     //
824     boolean redefineNodes(Dictionary *newdefs, Dictionary *olddefs);
825 
826     //
827     // Find the first free index (indices start from 1) for nodes with the
828     // given name.
829     // Currently, this only works for Input/Output nodes.
830     //
831     int findFreeNodeIndex(const char *nodename);
832 
isDeleted()833     boolean isDeleted() {return this->deleting;}
834 
835     int getNodeCount();
836 
837     //
838     // Place menu items (ButtonInterfaces) in the CascadeMenu, that when
839     // executed cause individually named panels and panel groups to be opened.
840     // If a PanelAccessManager, then only those ControlPanels defined to be
841     // accessible are placed in the CascadeMenu.
842     // NOTE: to optimize this method, if the menu is returned deactivated()
843     //   it may not contain the correct contents and so should no be activated()
844     //   except through subsequent calls to this method.
845     //
846     void fillPanelCascade(CascadeMenu *menu, PanelAccessManager *pam);
847 
848     //
849     // Merge two nets together, resolving instance collisions.  Delete the
850     // net being passed in.
851     //
852     // The stitch param (added 11/8/02) indicates what should be done when the
853     // incoming network has type/instance number conflicts with the existing
854     // network.  In the stitch case, the conflicts should be resolved by
855     // deleting the node in the incoming network and shifting its wires over
856     // to the conflicted node in the existing network.  The use of this is
857     // undoing a deletion of a set of nodes.
858     //
859     boolean mergeNetworks(Network *, List *panels, boolean all, boolean stitch=FALSE);
860     boolean mergePanels (Network *);
861 
862     //
863     // The decorators are held in this->decoratorList (no interactors in the list)
864     //
865     void addDecoratorToList (void *e);
866     void removeDecoratorFromList (void *e);
getDecoratorList()867     const List* getDecoratorList() { return &this->decoratorList; }
868 
869     //
870     // get and set x,y,width,height of a net in the vpe
871     //
872     void setTopLeftPos(int, int);
873     void getBoundingBox (int *x1, int *y1, int *x2, int *y2);
874 
875     //
876     // look through the network list and make a node list of the given class.
877     // If classname == NULL, then all nodes are included in the list.
878     // If classname != NULL, and includeSubclasses = FALSE, then nodes must
879     // be of the given class and not derived from the given class.
880     // If no nodes were found then NULL is returned.
881     // The returned List must be deleted by the caller.
882     //
883     List *makeClassifiedNodeList(const char *classname,
884 				 boolean includeSubclasses = TRUE);
885 
886     List *makeNamedControlPanelList(const char *name);
887     List *makeLabelledNodeList(const char *label);
888 
889     //
890     // Search the network for a node of the given class and return TRUE
891     // if found.
892     //
893     boolean containsClassOfNode(const char *classname);
894 
895     //
896     // look through the network list and make a list of the nodes with
897     // the give name.
898     // If no nodes were found then NULL is returned.
899     // The returned List must be deleted by the caller.
900     //
901     List *makeNamedNodeList(const char *nodename);
902 
isReadingNetwork()903     boolean isReadingNetwork() { return this->readingNetwork; }
904 
905 #ifdef DXUI_DEVKIT
906     //
907     // Print the visual program as a .c file that uses libDX calls.
908     // If the filename does not have a '.c' extension, one is added.
909     // An error message is printed if there was an error.
910     //
911     boolean saveAsCCode(const char *filename);
912 
913 #endif // DXUI_DEVKIT
914 
915     //static void        Network::GetDestinationNodes (Node*, int, List*, List*);
916 
917 
918 
919     //
920     // Optimally set the output cacheability of all nodes within the network.
921     // We only operate on those that have writable cacheability.
922     //
923     void optimizeNodeOutputCacheability();
924 
925 
wasNetFileEncoded()926     boolean wasNetFileEncoded() { return this->netFileWasEncoded;}
927 
928     //
929     // See if the given label is unique among nodes requiring uniqueness.
930     // Return NUL(char*) if unique.  Otherwise return the node name of the
931     // guy with whom we have a conflict.
932     //
933     const char* nameConflictExists(UniqueNameNode* passed_in, const char* label);
934     const char* nameConflictExists(const char* label);
935 
936 
937     //
938     // Maintain a list of transmitters which need fixing up after a network read.
939     // Older versions of dx weren't restrictive about name conflicts.  Now it
940     // you aren't allowed name conflicts among Transmitter,Receiver,Input,Output.
941     // So when reading a net with a name conflict, let it pass.  Just maintain a list
942     // of the conflicts and go back and fix them after the read.
943     // It's only necessary to fix the transmitters because changing them automatically
944     // fixes the receivers. (See renameTransmitters(), and RenameList.)
945     // If/when fixes are applied, we'll form a message string to show the user and
946     // store the string in a list.  EditorWindow can show the list if/when there
947     // is a vpe for the network.  No vpe/no display messages.
948     //
949     void fixupTransmitter(TransmitterNode*);
950     void renameTransmitters();
951     List* editorMessages;
952     void addEditorMessage(const char* msg);
953     void showEditorMessages();
954 
955     //
956     // Called by Remove/AddNodeWork(), but can also be called directly.
957     // This had always been protected but is now public because we need to
958     // revisit command activation for reasons other than adding/removing nodes.
959     //
960     virtual void changeExistanceWork(Node *n, boolean adding);
961 
962 #if WORKSPACE_PAGES
getGroupManagers()963     Dictionary* getGroupManagers() { return this->groupManagers; }
964     void	copyGroupInfo (Node* , List* );
965     void	copyGroupInfo (Node* , Node* );
966     boolean	chopArks(List*, Dictionary*, Dictionary*);
967     boolean	replaceInputArks(List*, List*);
968 #endif
969 
isJavified()970     virtual boolean isJavified() { return FALSE; }
971 
972     //
973     // Returns a pointer to the class name.
974     //
getClassName()975     const char* getClassName()
976     {
977 	return ClassNetwork;
978     }
979 };
980 
981 
982 #endif // _Network_h
983 
984