source: cpp/frams/canvas/neurodiagram.cpp @ 254

Last change on this file since 254 was 254, checked in by Maciej Komosinski, 9 years ago

More color definitions in neural diagrams

  • Property svn:eol-style set to native
File size: 17.7 KB
RevLine 
[151]1// This file is a part of the Framsticks GDK.
[197]2// Copyright (C) 1999-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
[151]3// Refer to http://www.framsticks.com/ for further information.
4
[147]5#include "neurodiagram.h"
6#include "nn_layout.h"
7#include <frams/neuro/neurolibrary.h>
8#include <frams/mech/mechworld.h>
9#include <frams/util/multirange.h>
10#include "canvasutil.h"
11#include <frams/neuro/neuroimpl.h>
12#include <frams/model/modelobj.h>
13#include <frams/simul/simul.h>
14#include "common/nonstd_time.h"
15
16#define FIELDSTRUCT NeuroDiagram
17ParamEntry neurodiagram_paramtab[] =
18{
19        { "NeuroDiagram", 1, 4, "NeuroDiagram", "Can be used as the client object in the Window.", },
20        { "new", 0, PARAM_USERHIDDEN, "create new NeuroDiagram", "p oNeuroDiagram", PROCEDURE(p_new), },
[240]21        { "showCreature", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "show dynamic NN", "p(oCreature)", PROCEDURE(p_showcr), },
22        { "showModel", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "show static NN", "p(oModel)", PROCEDURE(p_showmod), },
23        { "hide", 0, PARAM_USERHIDDEN | PARAM_NOSTATIC, "hide NN", "p()", PROCEDURE(p_hide), },
[147]24        { 0, 0, 0, },
25};
26#undef FIELDSTRUCT
27
28Param neurodiagram_param(neurodiagram_paramtab, 0);
29
30static struct ColorDefs colordefs;
31
32void NeuroDiagram::p_new(ExtValue*args, ExtValue*ret)
33{
34        NeuroDiagram *d = new NeuroDiagram(&colordefs);
35        d->drawbackground = false;
36        ret->setObject(ExtObject(&neurodiagram_param, d));
37}
38
39void NeuroDiagram::p_showcr(ExtValue*args, ExtValue*ret)
40{
41        Creature *cr = 0;
42        if (args->type == TObj)
43        {
44                const ExtObject& o = args->getObject();
45                cr = (Creature*)o.getTarget();
46        }
47        showLive(cr);
48}
49
50void NeuroDiagram::p_showmod(ExtValue*args, ExtValue*ret)
51{
52        Model *mod = ModelObj::fromObject(args[0]);
53        show(mod);
54}
55
56static void addNeuroDescription(SString &t, Neuro *n)
57{
58        static Param par;
59        SString c(n->getClassName());
60        NeuroClass* cl = n->getClass();
61        t += c;
62        t += " (";
63        if (cl)
64                t += cl->getLongName();
65        else
66                t += "Unknown";
67        t += ")";
68}
69
70NeuroDiagram::NeuroDiagram(ColorDefs *cd)
71:FramDrawToolkit(cd), livewire(false), indestructor(false), showing_not_alive_label(false), o(0),
72warn_if_not_alive(true), selection(*this), drawbackground(true), linetype(true), layouttype(2)
73{
74        scroll.setMargin(10, 10); // appropriate size should be adjusted
75        dontPaintOutside(0);
76        add(&scroll);
77        pluginactive = false;
78        FramDrawToolkit::setBackColor(ColorDefs::neurobackground);
79}
80
81NeuroDiagram::~NeuroDiagram()
82{
83        indestructor = 1;
84        hide();
85        remove(&scroll);
86        updatePlugin();
87}
88
89void NeuroDiagram::hide()
90{
91        showing_not_alive_label = 0;
92        if (o) o->delmodel_list.remove(killnode);
[151]93        FOREACH(NeuroProbe*,pr,probes)
94                delete pr;
[147]95        probes.clear();
96        selection.clear(0);
97        cr = 0;
98        livewire = false;
99}
100
101class NNLayoutState_Neurodiagram : public NNLayoutState
102{
103public:
104        NeuroDiagram *nd;
105        NNLayoutState_Neurodiagram(NeuroDiagram *_nd) :nd(_nd) {}
106
107        int GetElements()
108        {
109                return nd->scroll.count();
110        }
111
112        int *GetXYWH(int el)
113        {
114                return &nd->scroll.getInfo(el)->pos.x;
115        }
116
117        void SetXYWH(int el, int x, int y, int w, int h)
118        {
119                ScrollInfo *si = nd->scroll.getInfo(el);
120                si->pos.set(x, y); si->size.set(w, h);
121        }
122
123        int GetInputs(int el)
124        {
125                return nd->getNS(el)->n->getInputCount();
126        }
127
128        int GetLink(int el, int i)
129        {
130                return nd->getNS(el)->n->getInput(i)->refno;
131        }
132
133        int *GetLinkXY(int el, int i)
134        {
135                static int XY[2];
136                int *xywh = GetXYWH(el);
137                XY[0] = 0;
138                XY[1] = ((1 + i)*xywh[3]) / (GetInputs(el) + 1);
139                return XY;
140        }
141};
142
143
144void NeuroDiagram::show(Model *o_)
145{
146        hide();
147        o = o_;
148        scroll.removeAll();
149        if (o)
150        {
151                Neuro *n;
152                int i;
153                killnode = o->delmodel_list.add(STATRICKCALLBACK(this, &NeuroDiagram::onKill, 0));
154
155                // create symbol objects
156                for (i = 0; n = o->getNeuro(i); i++)
157                {
158                        NeuroSymbol *ns = new NeuroSymbol(*this, n);
159                        scroll.add(ns, 1); // autodel   
160                }
161                if (i)
162                {
163                        struct NNLayoutFunction *nnfun = &nn_layout_functions[layouttype];
164                        NNLayoutState_Neurodiagram nn(this);
165                        nnfun->doLayout(&nn);
166                }
167                scroll.invalidate();
168                scroll.autoZoom();
169        }
170
171        updatePlugin();
172        requestPaint();
173}
174
175void NeuroDiagram::showLive(Creature *_cr)
176{
177        showing_not_alive_label = 0;
178        if (!_cr) { show(0); return; }
179        show(&_cr->getModel());
180        cr = _cr;
181        livewire = true;
182        updatePlugin();
183}
184
185void NeuroDiagram::paint()
186{
187        if (drawbackground)
188        {
189                setColor(ColorDefs::neurobackground);
190                clear();
191        }
192
193        if (countNeurons() > 0)
194        {
195                CanvasWindowContainer::paint();
196        }
197        else
198        {
199                setColor(ColorDefs::neuroneuron);
200                drawAlignedText(size.x / 2, (size.y - textHeight()) / 2, 0, "[No neural network]");
201        }
202
203        if (showing_not_alive_label)
204        {
205                if (time(0) > showing_not_alive_label)
206                        showing_not_alive_label = 0;
207                else
208                {
209                        setColor(0, 0, 0);
210                        drawAlignedText(not_alive_location.x, not_alive_location.y, 0, "select a creature");
211                        drawAlignedText(not_alive_location.x, not_alive_location.y + textHeight(), 0, "to probe neurons");
212                }
213        }
214}
215
216void NeuroDiagram::resize(int w, int h)
217{
218        CanvasWindowContainer::resize(w, h);
219        scroll.autoZoom();
220}
221
222int NeuroDiagram::countNeurons()
223{
224        return scroll.count();
225}
226
227void NeuroDiagram::addProbe(int i)
228{
229        if (i >= countNeurons()) return;
230        NeuroProbe *probe = new NeuroProbe(getNS(i));
231        probes += (void*)probe;
232        add(probe);
233        updatePlugin();
234        requestPaint();
235}
236
[247]237void NeuroDiagram::onKill(void*obj, intptr_t dummy)
[147]238{
239        show(0);
240}
241
242///////////////////////////
243
244NeuroSymbol::NeuroSymbol(NeuroDiagram &nd, Neuro * _n)
[254]245        :selected(0), n(_n), diagram(nd), FramDrawToolkit(nd.getColorDefs())
[147]246{
247        tooltip = "#";
248        tooltip += SString::valueOf((int)n->refno);
249        tooltip += " - ";
250        label = tooltip;
251        addNeuroDescription(tooltip, n);
252        label += n->getClassName();
253        if (n->getClassParams().len())
254        {
255                tooltip += "\n"; tooltip += n->getClassParams();
256        }
257}
258
259void NeuroSymbol::paint()
260{
261        if (selected)
262        {
[254]263                setColor(ColorDefs::neuroselection);
[147]264                fillRect(0, 0, size.x, size.y);
265        }
266        diagram.setClip();
267        diagram.setColor(ColorDefs::neuroneuron);
268        drawNeuroSymbol(this, n->getClass(), 0, 0, size.x, size.y);
269
270        if (size.y > 4 * textHeight())
271        {
272                const char* t = label;
[254]273                setColor(ColorDefs::neurosymbol);
[147]274                drawAlignedText(size.x / 2, size.y - textHeight(), 0, t);
275
276                NeuroImpl *ni = NeuroNetImpl::getImpl(n);
277                if (ni && (ni->getChannelCount() > 1))
278                {
279                        drawLine(size.x - size.x / 16, size.y / 2 - size.y / 16,
280                                size.x - size.x / 8, size.y / 2 + size.y / 16);
281                        char t[20];
282                        sprintf(t, "%d", ni->getChannelCount());
283                        moveTo(size.x, size.y / 2 - textHeight());
284                        drawText(t);
285                }
286        }
287
[162]288/*
289
290            NeuroDiagram
291            *........................................
292            .                                       .
293            .                    NeuroSymbol        .
294            .      (pos.x,pos.y)-*.........         .
295            .                    . |\     . ^  s    .
296            .            ..._____._| \    . |  i    .
297            .                    . |  \___. |  z    .
298            .                  __._|  /   . |  e    .
299            .                 |  . | /    . |  .    .
300            .                 |  . |/     . |  y    . 
301            .                 |  .......... v       . 
302            .                 |  <-------->         . 
303            .      .......... |    size.x           .
304            .      . |\     . |                     .
305            .    __._| \    . |                     .
306            .      . |  \___._|                     .
307            .    __._|  /   .                       .
308            .   |  . | /    .                       .
309            .   |  . |/     .                       .
310            .   |  ..........                       .
311            .   |                                   .
312            .   |________________...                .
313            .........................................
314
315 */
316
[147]317        // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs
318        NeuroSymbol *ns2;
319        if (!diagram.isLive())
320                diagram.setColor(ColorDefs::neurolink);
321        for (int iw = 0; iw < n->getInputCount(); iw++)
322        {
[151]323                ns2 = diagram.getNS(n->getInput(iw)->refno); // the other NeuroSymbol (our input will connect to its output)
[147]324
325                int yw = inputY(iw);
[151]326                int xw = yw / 4; // x coordinate of the first corner point, depends on yw to avoid overlapping between inputs
[147]327                drawLine(size.x / 4, yw, xw, yw); // first horizontal segment (to the left)
[254]328                if (diagram.isLive())
329                        diagram.setWireColor(ns2->n->state, 0);
[213]330                // linetype: 1 (default) - draw straight or U-shape depending on layout
331                //           0 (debug option) - only draw straight lines
[147]332                if ((diagram.linetype != 1) || (ns2->pos.x + ns2->size.x / 2 < pos.x))
[151]333                { // straight line to the other neuron's output (the signal goes forwards)
[147]334                        ns2->lineTo(ns2->size.x, ns2->size.y / 2);
335                }
336                else
[151]337                { // make an U-shaped loop from 3 segments - vert/horiz/vert (the signal goes backwards)
[147]338                        int y2;
339                        int down;
340                        if (ns2 == this) down = (iw >= ((n->getInputCount()) / 2)); else down = (ns2->pos.y > (pos.y + size.y));
341                        if (down)
342                        {
343                                y2 = (pos.y + size.y + (size.y - yw) / 3);
344                        }
345                        else
346                        {
347                                y2 = pos.y - yw / 3;
348                                if ((ns2->pos.y<pos.y) && (ns2->pos.y>(pos.y - ns2->size.y))) y2 -= pos.y - ns2->pos.y;
349                        }
350                        // note: "diagram" uses global coordinate system, so we add "pos" or "ns2->pos" to get NeuroSymbol's global positions
351                        diagram.lineTo(pos.x + xw, y2);
352                        diagram.lineTo(ns2->pos.x + ns2->size.x, y2);
353                        diagram.lineTo(ns2->pos.x + ns2->size.x, ns2->pos.y + ns2->size.y / 2);
354                }
355
356        }
357}
358
359void NeuroSymbol::mouse(int x, int y, int t)
360{
361        if ((t & (LeftButton | ShiftButton)) == (LeftButton | ShiftButton))
362        {
363                ScrollManager& sc = diagram.scroll;
364                sc.setPos2(n->refno, pos.x + x - diagram.symboldragpos.x, pos.y + y - diagram.symboldragpos.y);
365                sc.validate();
366                requestPaint();
367        }
368}
369
370int NeuroSymbol::mouseclick(int x, int y, int t)
371{
372        if ((t & (LeftButton | DblClick)) == (LeftButton | DblClick))
373        {
374                if (diagram.isLive())
375                        diagram.addProbe(n->refno);
376                else
377                {
378                        if (diagram.warn_if_not_alive)
379                        {
380                                diagram.showing_not_alive_label = time(0) + 10;
381                                diagram.not_alive_location.x = pos.x + x;
382                                diagram.not_alive_location.y = pos.y + y;
383                                diagram.requestPaint();
384                        }
385                }
386                return LeftButton | DblClick;
387        }
388
389        if ((t & (LeftButton | ShiftButton)) == (LeftButton | ShiftButton))
390        {
391                if (selected)
392                        diagram.selection.remove(Model::neuroToMap(n->refno));
393                else
394                        diagram.selection.add(Model::neuroToMap(n->refno));
395                diagram.symboldragpos.set(x, y);
396                return LeftButton | ShiftButton;
397        }
398
399        if (t & LeftButton)
400        {
401                diagram.selection.set(Model::neuroToMap(n->refno));
402                return LeftButton;
403        }
404
405        return 0;
406}
407
408// coordinate y of i-th input
409int NeuroSymbol::inputY(int i)
410{
411        return (1 + i)*size.y / ((n->getInputCount()) + 1);
412}
413
414SString NeuroSymbol::hint(int x, int y)
415{
416        if ((y >= 0) && (y < size.y))
417                if (x<size.x / 4)
418                { // inputs?
419                        if (n->getInputCount()>0)
420                        {
421                                int i = (y*n->getInputCount()) / size.y;
422                                double w;
423                                Neuro* target = n->getInput(i, w);
424                                if (target)
425                                {
426                                        SString t = "connected to #";
427                                        t += SString::valueOf((int)target->refno);
428                                        t += " - ";
429                                        addNeuroDescription(t, target);
430                                        //              if (w!=1.0)
431                                        {
432                                                t += ", weight=";
433                                                t += SString::valueOf(w);
434                                        }
435                                        return t;
436                                }
437                        }
438                }
439        return CanvasWindow::hint(x, y);
440}
441
442/////////////////////////
443
444NeuroProbe::NeuroProbe(NeuroSymbol* ns)
445:DCanvasWindow(DCanvasWindow::Title + DCanvasWindow::Border + DCanvasWindow::Close + DCanvasWindow::Size,
[254]446  (const char*)ns->getLabel(), &neurochart, &neurochart)
[147]447{
448        holdismine = 0;
449        drawing = 0; whichdrawing = -1;
450        clientbordersset = 0;
451        adjustingvalue = 0;
452        link = ns;
453        tooltip = SString("Probe for ") + ns->tooltip;
454        setPos(ns->getPos().x, ns->getPos().y);
455        neurochart.printMinMax(0);
456        neurochart.data.setMinMax(-1, 1);
457        chnum = 1; chnum2 = 0; chsel = 0;
458        chselwidth = 0;
459        chselecting = 0;
460        updateChannelCount(NeuroNetImpl::getImpl(link->n));
461}
462
463void NeuroProbe::onClose()
464{
465        link->diagram.probes -= this;
466        delete this;
467}
468
469NeuroProbe::~NeuroProbe()
470{
471        if (holdismine)
472                link->n->flags &= ~Neuro::HoldState;
473}
474
475void NeuroProbe::paint()
476{
477        static char t[40];
478        if (!clientbordersset)
479        {
480                clientbordersset = 1;
481                setClientBorder(0, 1, 16, textHeight() + 2); // don't use textheight outside paint/mouse events
482        }
483        int hold = link->n->flags & Neuro::HoldState;
484        float state = (float)link->n->state;
485        NeuroImpl *ni = 0;
486        if (chsel != 0)
487        {
488                ni = NeuroNetImpl::getImpl(link->n);
489                if (chsel < 0)
490                {
491                        int dr = -chsel - 1;
492                        if (whichdrawing != dr)
493                        {
494                                drawing = ni->getDrawing(dr);
495                                whichdrawing = dr;
496                        }
497                        if (drawing)
498                        {
499                                int *dr = drawing;
500                                int w = size.x - 2, h = size.y - clienttop - clientbottom;
501                                int scale = min(w, h);
502                                int x0 = clienttop + leftborder + ((w > h) ? (w - h) / 2 : 0);
503                                int y0 = clientleft + topborder + ((h > w) ? (h - w) / 2 : 0);
504
505                                while (*dr != NeuroImpl::ENDDRAWING)
506                                {
507                                        int first = 1;
508                                        unsigned char r, g, b;
509                                        FramDrawToolkit::splitRGB(*(dr++), r, g, b);
510                                        setColor(r, g, b);
511                                        while (*dr != NeuroImpl::ENDDRAWING)
512                                        {
513                                                int x = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + x0;
514                                                int y = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + y0;
515                                                if (first) { moveTo(x, y); first = 0; }
516                                                else lineTo(x, y);
517                                        }
518                                        dr++;
519                                }
520                        }
521                }
522        }
523        DCanvasWindow::paintWithClient((chsel < 0) ? 0 : client);
524        setColor(0, 0, 0);
525        int yline = size.y - 2;
526        if (chsel >= 0)
527        {
528                if (ni) state = (float)ni->getState(chsel);
529                yline -= textHeight();
530                int y = mapClientY(neurochart.mapData(state));
531                int x = size.x - 15 - 1;
532                drawLine(1, yline, size.x - 2, yline);
533                if (hold)
534                {
535                        sprintf(t, "hold: %1.3g", state);
536                        fillRect(x, y - 1 - 5, 15, 3 + 5 + 5);
537                        setColor(255, 0, 0);
538                        fillRect(x + 2, y - 1, 15 - 2 - 2, 3);
539                }
540                else
541                {
542                        sprintf(t, "signal: %1.3g", state);
543                        fillRect(x, y - 1, 15, 3);
544                }
545                drawAlignedText(size.x - textHeight(), yline, 1, t);
546        }
547
548        if ((chnum > 1) || (chnum2 > 0))
549        {
550                if (chselecting) setColor(255, 255, 255); else setColor(0, 70, 0);
551                if (chsel < 0)
552                        sprintf(t, "%c/%c", 'A' - chsel - 1, 'A' + chnum2 - 1);
553                else
554                        sprintf(t, "%d/%d", chsel, chnum);
555                moveTo(0, yline - textHeight());
556                chselwidth = textWidth(t);
557                drawText(t, -1, getSize().x);
558        }
559        else
560                chselwidth = 0;
561}
562
563void NeuroProbe::mouse(int x, int y, int b)
564{
565        if (chselecting)
566        {
567                int ch = chsel0 + (x - chselx0) / 10;
568                if (selectChannel(ch)) requestPaint();
569                b &= ~LeftButton;
570        }
571        DCanvasWindow::mouse(x, y, b);
572        if (adjustingvalue)
573        {
574                double st = neurochart.unmapData(unmapClientY(y));
575                if (st<-1.0) st = -1.0; else if (st>1.0) st = 1.0;
576                if (chsel == 0)
577                        link->n->state = st;
578                else if (chsel >= 0)
579                {
580                        NeuroImpl *ni = NeuroNetImpl::getImpl(link->n);
[151]581                        if (ni) ni->setCurrentState(st, chsel);
[147]582                }
583                requestPaint();
584        }
585}
586
587void NeuroProbe::mouseunclick(int x, int y, int b)
588{
589        adjustingvalue = 0;
590        chselecting = 0;
591        DCanvasWindow::mouseunclick(x, y, b);
592}
593
594bool NeuroProbe::insideChSelector(int x, int y)
595{
596        if ((x > 0) && (x < chselwidth))
597        {
598                int sy = size.y;
599                if (chsel >= 0) sy -= textHeight();
600                return ((y<sy) && (y>(sy - textHeight())));
601        }
602        return 0;
603}
604
605int NeuroProbe::mouseclick(int x, int y, int b)
606{
607        if ((b & LeftButton) && insideChSelector(x, y))
608        {
609                chselx0 = x; chsel0 = chsel;
610                chselecting = 1;
611                requestPaint();
612                return LeftButton;
613        }
614        int ret = DCanvasWindow::mouseclick(x, y, b);
615        if (ret)
616        {
617                link->diagram.selection.set(Model::neuroToMap(link->n->refno));
618                return ret;
619        }
620        if (b & LeftButton)
621        {
622                if (x > size.x - 16)
623                {
624                        link->n->flags |= Neuro::HoldState;
625                        holdismine = 1;
626                        adjustingvalue = 1;
627                        mouse(x, y, b);
628                        return LeftButton;
629                }
630                else if (y > size.y - 16)
631                {
632                        link->n->flags ^= Neuro::HoldState;
633                        holdismine = ((link->n->flags&Neuro::HoldState) != 0);
634                        requestPaint();
635                        return LeftButton;
636                }
637        }
638        return 0;
639}
640
641SString NeuroProbe::hint(int x, int y)
642{
643        if ((chsel >= 0) && (x<size.x - 16) && (y>size.y - 16))
644                return SString((link->n->flags&Neuro::HoldState) ? "Click to release" : "Click to hold");
645        else if (insideChSelector(x, y))
646                return SString::sprintf("channel %d of %d (click and drag to switch channels)", chsel, chnum);
647        return DCanvasWindow::hint(x, y);
648}
649
650/** @return true == channel changed */
651bool NeuroProbe::selectChannel(int ch)
652{
653        if (ch < -chnum2) ch = -chnum2; else if (ch >= chnum) ch = chnum - 1;
654        if (ch == chsel) return false;
655        chsel = ch;
656        neurochart.data.clear();
657        return true;
658}
659
660void NeuroProbe::updateChannelCount(NeuroImpl *ni)
661{
662        if (!ni) return;
663        chnum = ni->getChannelCount();
664        chnum2 = ni->getDrawingCount();
665        if (chsel >= chnum) selectChannel(chnum - 1);
666        if (chsel < -chnum2) selectChannel(-chnum2);
667}
668
669void NeuroProbe::sampling()
670{
671        NeuroImpl *ni = NeuroNetImpl::getImpl(link->n);
672        updateChannelCount(ni);
673        if (!chsel)
674                neurochart.data += (float)(link->n->state);
675        else
676                neurochart.data += (float)(ni->getState(chsel));
677        whichdrawing = -1;
678}
679
680////
681
[247]682void NeuroDiagram::probeSampling(void*obj, intptr_t dummy)
[147]683{
[151]684        FOREACH(NeuroProbe*,pr,probes) pr->sampling();
[147]685        requestPaint();
686}
687
688void NeuroDiagram::updatePlugin()
689{
690        //int needplugin=(!probes)>0;
691        bool needplugin = livewire;
692        if (needplugin == pluginactive) return;
693        if (needplugin)
694        {
695                if (!cr) return;
696                sim = cr->group->getLibrary().sim;
697                pluginnode = sim->l_plugin.add(STATRICKCALLBACK(this, &NeuroDiagram::probeSampling, 0));
698        }
699        else
700                sim->l_plugin.remove(pluginnode);
701        pluginactive = needplugin;
702}
703
704/////////////
705
706void NeuroDiagramSelection::updateSelection(MultiRange& newsel)
707{
708        MultiRange added = getAdded(newsel);
709        if (!added.isEmpty())
710        {
711                added.shift(Model::mapToNeuro(0));
712                added.intersect(0, diagram.countNeurons() - 1);
713                for (int i = 0; i < added.rangeCount(); i++)
714                {
715                        const IRange &r = added.getRange(i);
716                        for (int j = r.begin; j <= r.end; j++)
717                                diagram.getNS(j)->selected = 1;
718                }
719        }
720        MultiRange removed = getRemoved(newsel);
721        if (!removed.isEmpty())
722        {
723                removed.shift(Model::mapToNeuro(0));
724                removed.intersect(0, diagram.countNeurons() - 1);
725                for (int i = 0; i < removed.rangeCount(); i++)
726                {
727                        const IRange &r = removed.getRange(i);
728                        for (int j = r.begin; j <= r.end; j++)
729                                diagram.getNS(j)->selected = 0;
730                }
731        }
732        if (!diagram.indestructor) diagram.requestPaint();
733}
Note: See TracBrowser for help on using the repository browser.