When I open a particular Dxf file in LibreCAD, the command line dialog box in libreCAD says :
Invalid objects removed : 1
I want to detect this invalid object in my dxf file and remove it. When does an object become invalid? What does an invalid object mean?
Since I didn't receive any answers overe here, I decided to dig into the libreCAD source code, and found this in rs_graphic.cpp :
/**
* Removes invalid objects.
* #return how many objects were removed
*/
int RS_Graphic::clean()
{
// author: ravas
int how_many = 0;
foreach (RS_Entity* e, entities)
{
if (e->getMin().x > e->getMax().x
|| e->getMin().y > e->getMax().y
|| e->getMin().x > RS_MAXDOUBLE
|| e->getMax().x > RS_MAXDOUBLE
|| e->getMin().x < RS_MINDOUBLE
|| e->getMax().x < RS_MINDOUBLE
|| e->getMin().y > RS_MAXDOUBLE
|| e->getMax().y > RS_MAXDOUBLE
|| e->getMin().y < RS_MINDOUBLE
|| e->getMax().y < RS_MINDOUBLE)
{
removeEntity(e);
how_many += 1;
}
}
The above code is self-explanatory and I hope this helps anyone who wonders the same question in future.
Related
I can't get my character to move backward or forwards- but left and right work perfectly fine! The inputs in the project are fine, there's nothing crazy I did with the physics on the rigidbody, I just can't seem to figure out the issue.
Portion of code pertaining to movement:
if (Input.GetAxis("Horizontal") > 0 || Input.GetAxis("Horizontal") < 0) {
gameObject.transform.GetComponent<Rigidbody>().MovePosition(gameObject.transform.position + (gameObject.transform.right * Input.GetAxis("Horizontal") * 10 * hSpeedMult * Time.deltaTime));
posAt = gameObject.transform.position;
}
else {
gameObject.transform.position = new Vector3(posAt.x, gameObject.transform.position.y, posAt.z);
}
if (Input.GetAxis("Vertical") > 0 || Input.GetAxis("Vertical") < 0) {
gameObject.transform.GetComponent<Rigidbody>().MovePosition(gameObject.transform.position + (gameObject.transform.forward * Input.GetAxis("Vertical") * 10 * vSpeedMult * Time.deltaTime));
posAt = gameObject.transform.position;
}
else {
gameObject.transform.position = new Vector3(posAt.x, gameObject.transform.position.y, posAt.z);
}
The "posAt" is just used to make sure the player cannot move when no controls are pressed.
Once I removed the "position freezer", it did the trick. My "PosAt" lines were the problem.
Currently, the software I support processes the different streams within a video container (.ts, .mp4, .mpg, etc) without any issues as long as there is only one(1) type of each codec stream.
I've recently encountered a video sample that actually contains three(3) identified AV_CODE_ID_SMPTE_KLV streams. As I loop through the three streams, one of them is the stream I need.
I haven't been able to figure out an easy way to do the specific query I need (check for known header bytes in the stream).
...
for (i = 0; i < nb_streams; i++) {
int real_stream_index = program ? program[i] : i;
AVStream *st = ic->streams[real_stream_index];
AVCodecParameters *par = st->codecpar;
if (par->codec_type != type)
continue;
if (id != AV_CODEC_ID_NONE) {
if (par->codec_id != id)
continue;
}
if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
continue;
if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
continue;
disposition = !(st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED | AV_DISPOSITION_VISUAL_IMPAIRED));
count = st->codec_info_nb_frames;
bitrate = par->bit_rate;
multiframe = FFMIN(5, count);
if ((best_disposition > disposition) ||
(best_disposition == disposition && best_multiframe > multiframe) ||
(best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
(best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
continue;
best_disposition = disposition;
best_count = count;
best_bitrate = bitrate;
best_multiframe = multiframe;
ret = real_stream_index;
My thought was to add another || to the complex if{} above, but I haven't been able to figure out how to do the comparison I need (looking for the header bytes).
I've looked into existing documentation, and thought that accessing the probe_data structure within the AVStream contained within the AVFormatContext structure would give me the first few bytes of the stream. No such luck, as the probe_data structure is empty even though we've done a probe on the file itself.
fprintf(stderr, "Filename: %s\t buf_size: %d\n", st-> probe_data.filename, st-> probe_data.buf_size);
I am working on a Project that requires me to place a BUYSTOP and a SELLSTOP pair of orders and then on the next bar if those orders are not triggered, then delete them and place fresh ones.
Here is my code:
if(logic == true && OrdersTotal() == 0)
{bool res = OrderSend(....);}
if(OrdersTotal() != 0)
{
if(ordertype == OP_BUY || ordertype == OP_SELL)
{
bool del = OrderDelete(....);
}
}
This code is properly placing orders and deleting them as well when I am testing.
But when the EA is active on the live server, it does not open orders because the platform already has orders of other instruments open.
I'm sure there would be quite an easy way to get around this but since I am a novice, I'm not able to figure that out.
it is not clear whether you use magic number and symbol check.
you should check sth like
int _ordersTotal = OrdersTotal()-1;
for (int i = _ordersTotal; i >= 0; i--){
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
....
}
in different realization, i.e. you can create a function(String Symbol) that checks if you have some working orders placed of the indicated Symbol.
Old proverb says:Measure twice before cut onceThere are actually four values ( three for pendings ) to check before OrderDelete()
As your definition states to handle { OP_{BUY|SELL}STOP } orders, there are following three items to check:
Symbol() match ( not causing unwanted side-effects by deleting other EA's or manual orders )
OrderType() match ( not ignoring the actual state { PENDING | AT_MARKET } and direction { BUY | SELL } of the order )
OrderMagicNumber() match ( not ignoring the UUID selector utility available to be set for each individual OrderSend() )
So, let's sketch the detection process:
int myEaContextAwareMagicNUMBER = ...;
for ( int ii = OrdersTotal();
ii >= 0;
ii--
)
if OrderSelect( ii, SELECT_BY_POS, MODE_TRADES )
{
if ( OrderSymbol() != _Symbol
&& OrderMagicNumber() != myEaContextAwareMagicNUMBER
&& OrderOpenTime() >= Time[1] // Prev. Bar
&& !( OrderType() == OP_BUYSTOP
|| OrderType() == OP_SELLSTOP
)
) continue; // __^ __^ __^ __^ __^ __^ loop for next test
// -------------------------------------------+
// FINALLY PROCESS THE MATCHING OrderDelete() |
// -------------------------------------------+
...
..
.
// -------------------------------------------+
}
else Print( "WARN: OrderSelect() failed at db.POOL.SELECT(), RECORD_NUMBER == ", ii );
So how to delete un-triggered pendings is done.
Next comes the remark about
"... when the ea is active on the live server, it does not open orders because the platform already has orders of other instruments open."
There could hardly be any advice provided without delivering the exact { GetLastError() | _LastError } values.
Some Brokers for some account types do indeed restrict OrderSend() acceptance policies, and thus besides the GetLastError() value the respective Broker Terms and Conditions apply.
Do not hesitate to ask more & may enjoy other Questions/Answers in MQL4 domain.
Please correct the below code:only.
file already contains entries : 1st row username; 2nd row password.
checkbox status required to write to the third line and need to read or alter only the checkbox status value in the file.
Currently this code is working if there already is a value for the checkbox status value, then it is overwriting, else UI is hanging.
WriteCheckStatusToFile(BOOL& locVar)
{
FILE *l_pFile = NULL;
CString l_strRememberCheck;
l_strRememberCheck = GetExePath() + _T("password");
CString sVar;
sVar.Format(_T("%d"),locVar);
if(NULL != (l_pFile = fopen(l_strRememberCheck, _T("r+"))) )
{
int count = 0;
char c;
while(count != 2)
{
if((c = fgetc(l_pFile)) == '\n') count++;
}
fseek(l_pFile,ftell(l_pFile),SEEK_SET);
fprintf(l_pFile, sVar);
}
l_strRememberCheck.ReleaseBuffer();
fclose(l_pFile);
}
thanks in advance to all!
sam.
This line
fprintf(l_pFile, sVar);
doesn't look right. I think it should be
fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
The loop could become infinite if the file has less than two linefeeds:
while(count != 2)
I think it should be:
while( (count < 2) && ( ! feof(l_pFile) ) && ( c != EOF ) )
Probably unrelated to your error, but - at least for this code snippet - CString::ReleaseBuffer() doesn't need to be called since you have not called CString::GetBuffer().
l_strRememberCheck.ReleaseBuffer();
This line may be unnecessary as it appears to fseek() to where the file pointer already is:
fseek(l_pFile,ftell(l_pFile),SEEK_SET);
In the event a two-line file is not terminated with a '\n' you would need to print like this:
if ( count == 2 )
{
fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
}
else
{
fprintf(l_pFile, "\n%s\n", (LPCTSTR) sVar);
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
i am getting "ranksection" array at run time and after implementing ksort on "ranksection" i wanna move its data upward on null index as i am printing ranksection before moving its data upward if there were any free array i am successfully getting what i want but it also giving error "Undefined Index" i dont know why my code is,
$sortvar = count($ranksection);
$seqnum = 0;
for ($var = 0; $var <= $sortvar; $var++) {
if ($ranksection[$var] != null) {
$sequence[$seqnum] = $ranksection[$var];
$seqnum++;
}
}
print_r($sortvar);
print_r($ranksection);
print_r($sequence);
the result is,
3
Array ( [1] => Self Introduction [2] => Experience in Econometrics and multivariate S [3] => Experience )
Array ( [0] => Self Introduction [1] => Experience in Econometrics and multivariate S [2] => Experience )
Hopes for your suggestions
See your print_r section of second array it starts with index 1 and your $var assigned to 0.
Now here you are trying to access the 0th index. that is why you're getting this error.
Try to use foreach
foreach($ranksection as $key => $value ) {
if ($ranksection[$key] != null) {
$sequence[$seqnum] = $ranksection[$key];
$seqnum++;
}
}
Do this as the condition for your for loop:
for ($var = 0; $var <= $sortvar - 1; $var++) {
The -1 is important since arrays start from 0 and go the length of the array, minus one.
You ought to be using count()-1 in your for loop:
$sortvar = count($ranksection) -1;
$seqnum = 0;
for ($var = 0; $var <= $sortvar; $var++) {
Or, use less than (without less than equal to) as the operator:
for ($var = 0; $var < $sortvar; $var++) {
You're going past the end of your array because:
$sortvar = count($ranksection); // This is 4
Array indexs start at 0, but count returns the number where 1 is the first item, not 0. Do this to fix it:
$sortvar = count($ranksection) - 1;
Or change <= to <
for ($var = 0; $var < $sortvar; $var++) {
if ($ranksection[$var] != null) {
$sequence[$seqnum] = $ranksection[$var];
$seqnum++;
}
}