How to set margin masks in Scintilla? - c++

I have a problem understanding how Scintilla markers are bound to a margin.
Lets say I want 3 margins. 1st for linenumbers (no problem here), 2nd for arrow markers only and 3rd for circle makers only. I know from the documentation that I have to specify marginmasks to bind a marker to a margin, but I don't get how to specify the mask. I tried around a little but never got the wanted result. (Either arrows were displayed on both margings (2nd and 3rd) or no symbol was highlighted and instead the line was highlighed). Hope someone can enlighten me how to set the marginmasks.
/* 2nd marker margin -> only arrows */
Call(SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL);
Call(SCI_SETMARGINWIDTHN, 1, 20);
Call(SCI_SETMARGINSENSITIVEN, 1, 1);
Call(SCI_SETMARGINMASKN, 1, SC_MARK_ARROW); // <=== ???
DefineMarker(1, SC_MARK_ARROW, 0xffffff, 0x0000ff);
/* 3rd marker margin -> only circles */
Call(SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);
Call(SCI_SETMARGINWIDTHN, 2, 50);
Call(SCI_SETMARGINSENSITIVEN, 2, 1);
DefineMarker(2, SC_MARK_CIRCLE, 0xffffff, 0x00ff00);
Call(SCI_SETMARGINMASKN, 2, SC_MARK_CIRCLE); // <=== ???
Call(SCI_MARKERADD, 1, 1);
Call(SCI_MARKERADD, 1, 2);
That way I get an arrow marker on margin 1 but only a highlighted line and no circle marker for margin 2. I would be glad if someone can explain how the masks have to be set.

There are 32 markers available, and numbers 0 to 24 have no pre-defined use. The numbers 25 to 31 are used for folding, but if you don't need that, you could use those numbers as well.
The first step is to choose a number for each of the markers you want to set up: let's say 4 for arrows, and 5 for circles (probably some constants should be defined for these).
The margin mask is a 32-bit value. To set it, you need to flip the bit that corresponds with each of the marker numbers that should be enabled for that margin:
Call(SCI_SETMARGINMASKN, 1, 1 << 4); // 2nd margin, arrow marker
Call(SCI_SETMARGINMASKN, 2, 1 << 5); // 3rd margin, circle marker
Then you need to define the markers themselves:
DefineMarker(4, SC_MARK_ARROW, 0xffffff, 0x0000ff);
DefineMarker(5, SC_MARK_CIRCLE, 0xffffff, 0x00ff00);
So you can finally add them to a specific line:
Call(SCI_MARKERADD, 1, 4);
Call(SCI_MARKERADD, 1, 5);

Related

How to recode missing values within a range in Stata

I asked a similar question earlier. I'm attempting to fill in missing values such that observations 0-458 are e 0, 445-832 are 1, and 832-850 are 0.
The following code allowed me to replace missing values in observations 1-160 with 1, with the rest of the observations set to 0.
replace myvar = cond(_n <= 160, 1, 0) if missing(myvar)
How can I interpret this command for what my current purpose?
There is no observation 0. I assume you meant observation 1. Your rules are ambiguous otherwise as you give two rules for 445-458 and two rules for 832.
I will give code for a minimal data example.
clear
set obs 6
gen myvar = .
Assume you want myvar in observations 1/2 to be 0, 3/4 to be 1, 5/6 to be 0.
Method 1
replace myvar = inrange(_n, 3, 4) if missing(myvar)
Method 2
replace myvar = cond(_n <= 2, 0, cond(_n <= 4, 1, 0))
Method 3
replace myvar = 0 if missing(myvar) in 1/2
replace myvar = 1 if missing(myvar) in 3/4
replace myvar = 0 if missing(myvar) in 5/6
In general, however, replacing in terms of observation numbers is not best technique. It is utterly dependent on sort order. Also, if there are criteria in terms of other variables, they are preferable as making more and better sense in records of reproducible research, to yourself in the future and to colleagues, reviewers and yet others too.

How to draw desired matrix using c++?

Draw below matrix using c++. Problem require a function, which could be called into the main().
x!x!x
~~~~~
x!x!x
~~~~~
x!x!x
I tried comparing the location 0,2,4. and tried to print but is there any other way to do this problem ?
If the matrix are characters, you could do something like this:
char board[] =
"x|x|x\n"
"-+-+-\n"
"x|x|x\n"
"-+-+-\n"
"x|x|x\n"
;
The columns containing the character 'x' are located at indices 0, 2, 4, 14, 16, 18, 26, 28, 30. Row indices are 0, 14, and 28.
Hint: there are 6 characters per row.
Hint: columns indices are (row * (characters per row)) + ((column - 1) * (2 characters per row))
This has the nice benefit of only requirement one statement to print:
std::cout.write(&board[0], sizeof(board) - 1U);
The - 1U is so that the terminating nul is not sent to cout.

Analytical flow-chart - decide what number should be in the box

I am having trouble in solving the following flowchart question. Could you please help me as soon as possible ?
Links are given below:-
Problem 3 and Problem 4:
http://placement.freshersworld.com/placement-papers/ThoughtWorks/Placement-Paper-Whole-Testpaper-29732
Problem 3:
Let's understand the instructions first.
Instruction 3 is a bit ambiguous whether it's referring to the box number or the number in the box. This becomes more straightforward when you read the rest of the instructions all referring to making changes to instruction 2. So we can conclude it means the first box number which is also the first number mentioned in the instruction's text rather than the number in the box.
Instruction 4 is a bit confusing due to its seemingly superfluous usage of the word "whose". If instruction 4 is interpreted to mean look at the number in box 6 and go to that instruction number, if you try to work out the rest of the problem, we have an infinite loop. But if we interpret it to mean:
boxes[boxes[6]] then we don't have an infinite loop.
Let's write some code, the following is JavaScript which you can execute in your JavaScript console, in chrome that is ctrl+shift+j:
var instruction2Variables=[null,1,10];
var boxes=[null,8,6,5,7,4,2,2,11,8,-2,2,1];
var instructions=[];
instructions[1]=function()
{
boxes[11]=boxes[11]+3;
};
instructions[2]=function()
{
instruction2Variables[2]=instruction2Variables[1];
};
instructions[3]=function()
{
return instruction2Variables[1]%2==1;
}
instructions[4]=function()
{
return boxes[boxes[6]];
}
instructions[5]=function()
{
instruction2Variables[1]+=2;
}
instructions[6]=function()
{
boxes[11]=boxes[5]+boxes[11];
}
instructions[7]=function()
{
instruction2Variables[1]+=boxes[12];
instruction2Variables[2]-=boxes[12];
}
instructions[8]=function()
{
return instruction2Variables[2]<boxes[1];
}
instructions[9]=function()
{
return 2;
}
var loops=0;
for(var i=1;i<10;i++)
{
loops++;
if(loops>1000){console.log('breaking an endless loop...');break;}
console.log('Instruction '+i);
var result=instructions[i]();
if(i==3)
{
if(!result){i=6;continue;}
}else if(i==4){
console.log('Going to instruction '+result);
i=result;continue;
}else if(i==8){
if(result){i=10;break;}
}
}
boxes.shift();//get rid of our leading null value
console.log(boxes);//[8, 6, 5, 7, 4, 2, 2, 11, 8, -2, 5, 1]
Problem 4:
First we need to realize the yes/no for instruction 3 is actually pointing the wrong way. There is no question in instruction 1, so the "no" result for instruction 3 is supposed to point upwards meaning to repeat instruction 1 again if "yes".
Instruction 2 seems to reference boxes beyond our 12 boxes at first glance, but it really means we're increasing where we're storing our result of what will always be zero.
Solving this is rather easy. Our first loop we will be storing a 0 in box 2. Our second loop we will be storing a 0 in box 4. Our third loop we will be storing a 0 in box 6. After this, we must stop the looping at exactly this point as-to not corrupt our data. Our answer at first glace seems to be 6, but we're changing our box data in instruction 1 and changing instruction 1 in instruction 2. So after we execute instruction 1 for a third time, we will have boxes 2,4, and 6 set to 0. Then we will run instruction 2 for a third time, thus increasing the box reference to box 8. Finally we want to break our loop, so we need box 3 to store a value of 8.

Mathematica solution?

I am new with Mathematica and I have one more task to figure out, but I can't find the answer. I have two lists of numbers ("b","u"):
b = {8.734059001373602`, 8.330508824111284`, 5.620669156438947`,
1.4722145583571766`, 1.797504620275392`, 7.045821078656974`,
2.1437334927375247`, 2.295629405840401`, 9.749038328921163`,
5.9928406294151095`, 5.710839663259195`, 7.6983109942364365`,
1.02781847368645`, 4.909108426318685`, 2.5860897177525572`,
9.56334726886076`, 5.661774934433563`, 3.4927397824800384`,
0.4570000499566351`, 6.240122061193738`, 8.371962670138991`,
4.593105388706549`, 7.653068139076581`, 2.2715973346475877`,
7.6234743784167875`, 0.9177107503732636`, 3.182296027902268`,
6.196168580445633`, 0.1486794884986935`, 1.2920960388213274`,
7.478757220079665`, 9.610332785387424`, 0.05088141346751485`,
3.940557901075696`, 5.21881311050797`, 7.489624788199514`,
8.773397599406234`, 3.397275198258715`, 1.4847171141876618`,
0.06574278834161795`, 0.620801320529969`, 2.075457888143216`,
5.244608900551409`, 4.54384757203616`, 7.114276285060143`,
2.8878711430358344`, 5.70657733453041`, 8.759173986432632`,
1.9392596667256967`, 7.419234634325729`, 8.258205508179927`,
1.185315253730261`, 3.907753644335596`, 7.168561412289151`,
9.919881985898002`, 3.169835543867407`, 8.352858871046699`,
7.959492335118693`, 7.772764587074317`, 7.091413185764939`,
1.433673058797801`};
and
u={5.1929, 3.95756, 5.55276, 3.97068, 5.67986, 4.57951, 4.12308,
2.52284, 6.58678, 4.32735, 7.08465, 4.65308, 3.82025, 5.01325,
1.17007, 6.43412, 4.67273, 3.7701, 4.10398, 2.90585, 3.75596,
5.12365, 4.78612, 7.20375, 3.19926, 8.10662};
This is the LinePlot of "b" and "u";
I need to compare first 5 numbers from "b" to 1st number in "u" and always leave the maximum (replace "b"<"u" with "u"). Then I need to shift by 2 numbers and compare 3rd, 4th, 5th, 6th and 7th "b" with 2nd "u" and so on (shift always => 2 steps). But the overlapping numbers need to be "remembered" and compared in the next step, so that always the maximum is picked (e.g. 3rd, 4th and 5th "b" has to be > than 1st and 2nd "u").
Possibly the easiest way would be to cover the maximums showed in the image throughout the whole function, but I am new to this software and I don't have the experience to do that. Still It would be awesome if someone would figure out how to do this with a function that would do what I have described above.
I believe this does what you want:
With[{n = Length # u},
Array[b[[#]] ~Max~ Take[u, ⌊{#-2, #+1}/2⌋ ~Clip~ {1, n}] &, 2 n + 3]
]
{8.73406, 8.33051, 5.62067, 5.1929, 5.55276, 7.04582, 5.55276, 5.55276, 9.74904,--
Or if the length of u and v are appropriately matched:
With[{n = Length # u},
MapIndexed[# ~Max~ Take[u, ⌊(#2[[1]] + {-2, 1})/2⌋ ~Clip~ {1, n}] &, b]
]
These are quite a lot faster than Mark's solution. With the following data:
u = RandomReal[{1, 1000}, 1500];
b = RandomReal[{1, 1000}, 3004];
Mark's code takes 2.8 seconds, while mine take 0.014 and 0.015 seconds.
Please ask your future questions on the dedicated Mathematica StackExchange site:
I think that there's a small problem with your data, u doesn't have as many elements as Partition[b,5,2]. Leaving that to one side, the best I could do was:
Max /# Transpose[
Table[Map[If[# > 0, Max[#, u[[i]]], 0] &,
RotateRight[PadRight[Partition[b, 5, 2][[i]], Length[b]],
2 (i - 1)]], {i, 1, Length[u]}]]
which starts producing the same numbers as in your comment.
As ever, pick this apart from the innermost expression and work outwards.

Multi-row text in heading

I'm working on a complex grid layout, and UltimateGrid is my choice.
I have set a multi-row heading, then I have joined some cells in heading vertically.
Now, I'm looking for a way to set multi-line text in heading cells which I have joined.
Here's an explanatory screenshot.
I already have tried by writing:
void MyCug::OnSetup(){
int rows = 5;
int cols = 20;
// setup rows and columns
SetNumberRows(rows);
SetNumberCols(cols);
// create 3 row top heading
SetTH_NumberRows(2);
...
JoinCells (16, -2, 16, -1); // Here I joins - in heading - two cells : row 16, columns -2 and -1
...
// Then I retrieve merged cell
CUGCell m_cell;
GetCell(16, -2, &m_cell);
// I need to show multi-line content in heading cells: I tried to set multi-row property.
int result = m_cell.SetPropertyFlags(m_cell.GetPropertyFlags() | UGCELL_MULTIROWCELL);
if (result == UG_SUCCESS) {
bool ok = true; // all seems to be ok...
}
m_cell.SetText("string\r\nstring\r\nstring"); // Despite my attempt, this will be always show on a single line!
SetCell(16, -3, &m_cell);
...
}
Without success: cell text is always shown on a single line, that is exactly what I don't want.
How can I get the cell text on multiple lines?
I tell how I have solved my problem, hoping it will be useful to someone.
To set multi-line cells, member function CUGCell::SetCellTypeEx() should be used.
This function allow you to set extended properties for single cells.
The example below works perfectly:
void MyCug::OnSetup(){
int rows = 5;
int cols = 20;
// setup rows and columns
SetNumberRows(rows);
SetNumberCols(cols);
// create 3 row top heading
SetTH_NumberRows(2);
...
JoinCells (16, -2, 16, -1); // Here i joins - in heading - two cells : row 16, columns -2 and -1
...
// I retrieve merged cell
CUGCell m_cell;
GetCell(16, -2, &m_cell);
cell.SetCellTypeEx(UGCT_NORMALMULTILINE); // set multiline cell
m_cell.SetText("string\r\nstring\r\nstring");
SetCell(16, -3, &m_cell);
}
Inside the OnSetup() method:
Set the number of rows in the top heading.
SetTH_NumberRows(2); // Set 2 rows
Join the range of cells together
JoinCells(1,-2, 1,-1); // Join row -1 and -2 in column 1
Add multiline feature to the cell
QuickSetCellTypeEx(1, -2, UGCT_NORMALMULTILINE); // Column 1, row -2 is a multiline
Add text
CString title = _T("New\r\nline");
QuickSetText(1, -2, title); SetColWidth(1, 200); // Set text in the preferred cell