Objects in JS

Objects in JS can be created by:

  1. Use of variables
  2. Use of functions
// table variable                      |              // use of function
var table = {                          |              var table = function() {
    "legs":4,                          |                  this.legs = 4;
    "color":"brown",                   |                  this.color = "brown";
    "material":"wood"                  |                  this.material = "wood";
};                                     |              };

An instance of these objects can be created as:

var myTable = new table();

Arguments can be passed as needed in the constructor with corresponding changes in definition of the constructor. All the variables defined as property of this are public. In order to make a variable private, var keyword is used. Private variables are created to control changes that happen to their values from outside. Functions to modify these values are then defined within the constructor. This is illustrated in Bike object below.

var car = function() {
    var speed = 20;            // private variable

    // public methods below
    this.accelerate = function(paceup) {
        speed += change;
    };

    this.decelerate = function() {
        speed -= 5;
    };

    this.getSpeed = function() {
        return speed;
    };
};

Selecting Matching Selectors when Objects are Selected

This post explains selection of treeview rows when objects belonging to that selector row are selected.

First, the objects in the desktop selection are obtained. Next the treeview’s rows are iterated and each row’s column _colObj is obtained as:
std::vector<spobject *> objVec = row[_mColumns._colObj];

The selected object’s ID is compared with each object’s ID in objVec. If the comparison returns true, then the row whose objVec had matching objects is added to treeview selection as:
_treeView.get_selection()->select(row);

By default, only the parent rows are iterated. So a check is also performed on child rows to see if IDs match with them. Also if there is a prior selection and the current object selected does not belong to any selector, then the treeview selection is cleared using _unselect_all() function of Gtk::TreeSelection.

Screenshot from 2016-07-27 13:50:02
In the above screenshot, the object associated with second child row is selected which in turn selects the row in treeview.

Selection of Objects when Style Dialog Row is Selected

Whenever any row in Style Dialog is selected, the corresponding objects in the drawing must be selected. This was implemented quickly. First the selection prior to selecting any row is cleared. Next it is made sure that the objects are selected only when the tree column corresponding to selector label is clicked. First column with ‘+’ is avoided because it is used to add objects to selector.

Next _colObj, i.e. the column referring to corresponding objects of the selected row is used to get the objects to be added to selection.

_desktop->selection->add(obj);

obj is the object in the objVec returned by _colObj. Thus objects are added to selection. Besides it is also checked, if the row selected in the Style Dialog is a parent row or a child row. For the former case, its child rows are also iterated and those objects are also added to selection.

Case 1: When parent row is selected and it has children
Screenshot from 2016-07-27 12:58:52

Case 2: When child row is selected
Screenshot from 2016-07-27 12:59:09

There will be another case in selection when matching selector rows should be seleted when objects in the drawing are selected, which will be discussed in next post.