Skip to content

Commit

Permalink
Find all instances feature #51.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Apr 4, 2020
1 parent bd64784 commit deba2ef
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PREFIX=/usr/local
# custom one that picks up its scripts from a relative library
# directory
MODLINK=$(LIBMODS:%=$(ECOLAB_HOME)/lib/%)
MODEL_OBJS=wire.o item.o group.o minsky.o port.o operation.o variable.o switchIcon.o godleyTable.o cairoItems.o godleyIcon.o SVGItem.o plotWidget.o canvas.o panopticon.o godleyTableWindow.o ravelWrap.o sheet.o CSVDialog.o selection.o parameterSheet.o variableSheet.o
MODEL_OBJS=wire.o item.o group.o minsky.o port.o operation.o variable.o switchIcon.o godleyTable.o cairoItems.o godleyIcon.o SVGItem.o plotWidget.o canvas.o panopticon.o godleyTableWindow.o ravelWrap.o sheet.o CSVDialog.o selection.o parameterSheet.o variableSheet.o variableInstanceList.o
ENGINE_OBJS=coverage.o derivative.o equationDisplay.o equations.o evalGodley.o evalOp.o flowCoef.o godleyExport.o \
latexMarkup.o variableValue.o node_latex.o node_matlab.o CSVParser.o minskyTensorOps.o
TENSOR_OBJS=hypercube.o tensorOp.o xvector.o
Expand Down
2 changes: 1 addition & 1 deletion ecolab
22 changes: 22 additions & 0 deletions gui-tk/minskyTCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define MINSKYTCL_H
#include "minsky.h"
#include "godleyTableWindow.h"
#include "variableInstanceList.h"
#include <fstream>
#include <memory>

Expand Down Expand Up @@ -305,6 +306,8 @@ namespace minsky
TCL_obj(minskyTCL_obj(),"minsky.canvas.model", *canvas.model);
}



std::string openGodley() {
if (auto gi=dynamic_pointer_cast<GodleyIcon>(canvas.item))
{
Expand All @@ -324,6 +327,25 @@ namespace minsky
return "";
}

std::string listAllInstances() const {
if (auto v=canvas.item->variableCast())
{
std::string name="instanceList"+to_string(size_t(canvas.item.get()));
if (TCL_obj_properties().count(name)==0)
{
auto instanceList=new VariableInstanceList(*canvas.model, v->valueId());
// pass ownership of object to TCL interpreter
Tcl_CreateCommand
(ecolab::interp(), (name+".delete").c_str(),
(Tcl_CmdProc*)deleteTclObject<VariableInstanceList>,
(ClientData)instanceList,NULL);
TCL_obj(minskyTCL_obj(),name,*instanceList);
}
return name;
}
return "";
}

void loadVariableFromCSV(const std::string& specVar, const std::string& filename)
{
auto i=TCL_obj_properties().find(specVar);
Expand Down
32 changes: 32 additions & 0 deletions gui-tk/wiring.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,36 @@ proc incrCase {delta} {
canvas.requestRedraw
}

proc gotoInstance {vid} {
global .instanceList$vid.variableList
[set .instanceList$vid.variableList].gotoInstance [.instanceList$vid.listbox curselection]
canvas.requestRedraw
}

proc deleteInstance vid {
global .instanceList$vid.variableList
if [llength [info commands [set .instanceList$vid.variableList].delete]] {
[set .instanceList$vid.variableList].delete
}
}

proc findAllInstances {} {
# check if variable selected
if {![llength [info commands minsky.canvas.item.valueId]]} return
set vid [minsky.canvas.item.valueId]
if {![winfo exists .instanceList[minsky.canvas.item.valueId]]} {
toplevel .instanceList$vid
listbox .instanceList$vid.listbox -listvariable .instanceList$vid.listIds -selectmode single
button .instanceList$vid.ok -text "OK" -command "destroy .instanceList$vid"
pack .instanceList$vid.listbox .instanceList$vid.ok
bind .instanceList$vid.listbox <Double-Button> "gotoInstance $vid"
}
global .instanceList$vid.listIds .instanceList$vid.variableList
set .instanceList$vid.variableList [listAllInstances]
set .instanceList$vid.listIds [[set .instanceList$vid.variableList].names]
bind .instanceList$vid <Destroy> "deleteInstance $vid"
raise .instanceList$vid
}

#
# context menu
Expand All @@ -648,6 +677,9 @@ proc contextMenu {x y X Y} {
.wiring.context add command -label "Select all instances" -command {
canvas.selectAllVariables
}
.wiring.context add command -label "Find all instances" -command {
findAllInstances
}
.wiring.context add command -label "Rename all instances" -command {
renameVariableInstances
}
Expand Down
14 changes: 6 additions & 8 deletions model/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ namespace minsky
if (i<bookmarks.size())
bookmarks.erase(bookmarks.begin()+i);
}
void gotoBookmark(size_t i) {
if (i<bookmarks.size())
{
auto& b=bookmarks[i];
moveTo(b.x, b.y);
zoom(x(),y(),b.zoom/(relZoom*zoomFactor()));
}
void gotoBookmark_b(const Bookmark& b) {
moveTo(b.x, b.y);
zoom(x(),y(),b.zoom/(relZoom*zoomFactor()));
}

void gotoBookmark(size_t i)
{if (i<bookmarks.size()) gotoBookmark_b(bookmarks[i]);}


};

Expand Down
56 changes: 56 additions & 0 deletions model/variableInstanceList.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
@copyright Steve Keen 2020
@author Russell Standish
This file is part of Minsky.
Minsky is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Minsky is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Minsky. If not, see <http://www.gnu.org/licenses/>.
*/

#include "variableInstanceList.h"
#include "group.h"
#include "selection.h"
#include "minsky_epilogue.h"

using namespace std;

namespace minsky
{
VariableInstanceList::VariableInstanceList(Group& model, const string& valueId):
model(model)
{
model.recursiveDo
(&Group::items,
[this,&valueId](const Items&, Items::const_iterator i) {
if (auto v=(*i)->variableCast())
if (v->valueId()==valueId)
{
bookmarks.emplace_back(this->model.x()-v->x()+50, this->model.y()-v->y()+50, v->zoomFactor(),
v->name()+"@("+to_string(int(v->x()))+","+to_string(int(v->y()))+")");
items.push_back(*i);
}
return false;
});
}

void VariableInstanceList::gotoInstance(size_t i) {
if (i<bookmarks.size())
{
assert(bookmarks.size()==items.size());
model.gotoBookmark_b(bookmarks[i]);
items[i]->selected=true;
}
}

}

56 changes: 56 additions & 0 deletions model/variableInstanceList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
@copyright Steve Keen 2020
@author Russell Standish
This file is part of Minsky.
Minsky is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Minsky is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Minsky. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef VARIABLEINSTANCELIST_H
#define VARIABLEINSTANCELIST_H
#include "bookmark.h"
#include "item.h"

#include <string>
#include <vector>

/// @file create a list of bookmarks for all instance of a variable on
/// current canvas

namespace minsky
{
class Group;

class VariableInstanceList
{
Group& model;
std::vector<Bookmark> bookmarks;
std::vector<ItemPtr> items;
public:
/// @param model top level group to obtain instances from
/// @param valueId id of variables to obtain the instances of
VariableInstanceList(Group& model, const std::string& valueId);
/// zoom model to instance number in the list
void gotoInstance(size_t);
/// return the list of names
std::vector<std::string> names() const {
std::vector<std::string> r;
for (auto& b: bookmarks) r.push_back(b.name);
return r;
}
};
}

#include "variableInstanceList.cd"
#endif

0 comments on commit deba2ef

Please sign in to comment.