Custom AIS_InteractiveObject -> Aspect Problem

Hi, I have a AIS_Vector class inherited from AIS_InteractiveObject to represent vectors (found in occ samples) but I can neither change the color nor the arrow aspect. It changes the aspect in ..::Compute(..) by myDrawer->SetArrowAspect(..) but nothing changes. I have also tried to changed color in constructor or in ..::Compute(..) but I could not succeed. How can I fix this?
Thanks

ATTIA's picture

Hello I have the same problem.
I want to change the color of my ARRow. I have used myAISContext->setColor(...) but Nothing is changed. I have used also ArrowAspect->setColor() but also Nothing is changed.
Thank you for your help

JuryS's picture

don't forget Update Object after you have change color.
It's work for me:

myObject->SetColor(color.Name());
myObject->Update();

ATTIA's picture

Thank you jury for your help but the line myObject->update() doesn't work. In fact this error appears
"PrsMgr_PresentableObject:: Update ': can not access protected member declared (e) in the class' PrsMgr_PresentableObject'"

JuryS's picture

Hi, I have this problem too, BUT with this code it's working:

#include "lineeditdialog.h"
#include "AnalizeMacro.h"
#include "mainwindow.h"

LineEditDialog::LineEditDialog(const TDF_Label LabObjec,const Handle_TPrsStd_AISPresentation CurrentPrs)
{
myObject = CurrentPrs;
myLabel = LabObjec;

//Ñîçäàþ äèàëîãîâîå îêíî
QPushButton *OK = new QPushButton(QPixmap(":/Visual3D/icons/Resurs/doc_apply.png"),trUtf8("Äàëåå"));
connect(OK, SIGNAL(clicked()), this, SLOT(execandquit()));
QPushButton *closeButton = new QPushButton(QPixmap(":/Visual3D/icons/Resurs/doc-close.png"),trUtf8("Îòìåíà"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
QHBoxLayout *ResultLayout = new QHBoxLayout;
ResultLayout->addWidget(OK);
ResultLayout->addWidget(closeButton);
ResultLayout->setSpacing(5);
ResultLayout->setMargin(2);

QLabel *X1lab = new QLabel("X1:");
QLabel *Y1lab = new QLabel("Y1:");
QLabel *Z1lab = new QLabel("Z1:");

X1Line = new QLineEdit;
Y1Line = new QLineEdit;
Z1Line = new QLineEdit;

QVBoxLayout *P1left = new QVBoxLayout;
P1left->addWidget(X1lab);
P1left->addWidget(Y1lab);
P1left->addWidget(Z1lab);
P1left->setSpacing(5);
P1left->setMargin(2);

QVBoxLayout *P1right = new QVBoxLayout;
P1right->addWidget(X1Line);
P1right->addWidget(Y1Line);
P1right->addWidget(Z1Line);
P1right->setSpacing(5);
P1right->setMargin(2);

QHBoxLayout *point1Layout = new QHBoxLayout;
point1Layout->addLayout(P1left);
point1Layout->addLayout(P1right);
point1Layout->setSpacing(5);
point1Layout->setMargin(2);

QGroupBox *point1 = new QGroupBox;
point1->setTitle(trUtf8("Êîîðäèíàòû ïåðâîé òî÷êè:"));
point1->setLayout(point1Layout);

QLabel *X2lab = new QLabel("X2:");
QLabel *Y2lab = new QLabel("Y2:");
QLabel *Z2lab = new QLabel("Z2:");

X2Line = new QLineEdit;
Y2Line = new QLineEdit;
Z2Line = new QLineEdit;

QVBoxLayout *P2left = new QVBoxLayout;
P2left->addWidget(X2lab);
P2left->addWidget(Y2lab);
P2left->addWidget(Z2lab);
P2left->setSpacing(5);
P2left->setMargin(2);

QVBoxLayout *P2right = new QVBoxLayout;
P2right->addWidget(X2Line);
P2right->addWidget(Y2Line);
P2right->addWidget(Z2Line);
P2right->setSpacing(5);
P2right->setMargin(2);

QHBoxLayout *point2Layout = new QHBoxLayout;
point2Layout->addLayout(P2left);
point2Layout->addLayout(P2right);
point2Layout->setSpacing(5);
point2Layout->setMargin(2);

QGroupBox *point2 = new QGroupBox;
point2->setTitle(trUtf8("Êîîðäèíàòû âòîðîé òî÷êè:"));
point2->setLayout(point2Layout);

QLabel *NoStColLab = new QLabel(trUtf8("Öâåò:"));

QToolButton* NoStColorSel = new QToolButton();
NoStColorSel->setIcon(QPixmap(":/Visual3D/icons/Resurs/colors.png"));
connect(NoStColorSel, SIGNAL(clicked()), this, SLOT(onColorClicked()));

QHBoxLayout *materialLayout = new QHBoxLayout;
materialLayout->addWidget(NoStColLab);
materialLayout->addWidget(NoStColorSel);
materialLayout->setSpacing(5);
materialLayout->setMargin(2);

QGroupBox *material = new QGroupBox;
material->setTitle(trUtf8("Öâåò:"));
material->setLayout(materialLayout);

NameEdit = new QLineEdit;
QHBoxLayout *NameLayout = new QHBoxLayout;
NameLayout->addWidget(NameEdit);
NameLayout->setSpacing(5);
NameLayout->setMargin(2);
QGroupBox *NameGroup = new QGroupBox;
NameGroup->setTitle(trUtf8("Èìÿ îáúåêòà:"));
NameGroup->setLayout(NameLayout);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(NameGroup);
mainLayout->addWidget(point1);
mainLayout->addWidget(point2);
mainLayout->addWidget(material);
mainLayout->addLayout(ResultLayout);
mainLayout->setSpacing(5);
mainLayout->setMargin(2);

QWidget *myWidget = new QWidget();
myWidget->setLayout(mainLayout);
setWidget(myWidget);

int myHeight, myWidth, myPosX, myPosY,isScroll=5;
if (myWidget->height()>QApplication::desktop()->height()-100)
{
myHeight = QApplication::desktop()->height()-100;
isScroll = 20;
}
else myHeight = myWidget->height()+5;
myWidth = myWidget->width()+isScroll; //+20 åñëè áóäåò ñêðîëëáàð âåðòèêàëüíûé
myPosX = QApplication::desktop()->width()/2-myWidth/2;
myPosY = (QApplication::desktop()->height() - myHeight)/2;
setGeometry(myPosX,myPosY,myWidth,myHeight);

setWindowFlags(Qt::Dialog);
setFixedSize(myWidth,myHeight);
setWindowIcon(QPixmap(":/Visual3D/Create2D/Resurs/2Dline.png"));
setWindowTitle(trUtf8("Ëèíèÿ (Line)"));

//! Ñ÷èòûâàþ àòðèáóòû ñ êîíêðåòíîé ëèíèè //â áåçîïàñíîì ðåæèìå//
bool isFound;

TDF_Label level1 = myLabel.FindChild(1,Standard_True);
Handle(TDataStd_Real) curReal;
isFound = level1.FindChild(1).FindAttribute(TDataStd_Real::GetID(),curReal);
x1=isFound ? curReal->Get() : 0;
isFound = level1.FindChild(2).FindAttribute(TDataStd_Real::GetID(),curReal);
y1=isFound ? curReal->Get() : 0;
isFound = level1.FindChild(3).FindAttribute(TDataStd_Real::GetID(),curReal);
z1=isFound ? curReal->Get() : 0;
isFound = level1.FindChild(4).FindAttribute(TDataStd_Real::GetID(),curReal);
x2=isFound ? curReal->Get() : 0;
isFound = level1.FindChild(5).FindAttribute(TDataStd_Real::GetID(),curReal);
y2=isFound ? curReal->Get() : 0;
isFound = level1.FindChild(6).FindAttribute(TDataStd_Real::GetID(),curReal);
z2=isFound ? curReal->Get() : 0;

TDF_Label level0 = myLabel.FindChild(0,Standard_True);
Handle_TDataStd_AsciiString curString;
TCollection_AsciiString AsciiName;
level0.FindChild(0).FindAttribute(TDataStd_AsciiString::GetID(),curString);
AsciiName = curString->Get();
m_Name=AsciiName.ToCString();

Handle_TDataStd_IntegerArray anArray = new TDataStd_IntegerArray();
isFound = level0.FindChild(1).FindAttribute(TDataStd_IntegerArray::GetID(),anArray);
R1 = isFound ? anArray->Value( 1 ) : 50; //Íàõîæó çíà÷åíèÿ öâåòîâûõ ñîñòàâëÿþùèõ
G1 = isFound ? anArray->Value( 2 ) : 50; //åñëè íåò, âîçâðàùàþ 0
B1 = isFound ? anArray->Value( 3 ) : 50;
//! Ñ÷èòûâàþ àòðèáóòû ñ êîíêðåòíîé ëèíèè

//Ïåðåäàþ ýòè àòðèáóòû â äèàëîãîâîå îêíî
X1Line->setText(QString::number(x1));
Y1Line->setText(QString::number(y1));
Z1Line->setText(QString::number(z1));
X2Line->setText(QString::number(x2));
Y2Line->setText(QString::number(y2));
Z2Line->setText(QString::number(z2));
NameEdit->setText(QString::fromUtf8(m_Name.toAscii().data()));

connect(X1Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(Y1Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(Z1Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(X2Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(Y2Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(Z2Line, SIGNAL(textChanged(QString)),this, SLOT(CoordChanged()));
connect(NameEdit, SIGNAL(textChanged(QString)),this, SLOT(NameChanged()));

isColor = false;
isName = false;
isCoordinate = false;
}

void LineEditDialog::execandquit()
{
if (isColor) R1=R1a, G1=G1a, B1=B1a;
a_Name = NameEdit->text().toUtf8();
a_Name.replace(QString(" "), QString("_"));
//Åñëè ãåîìåòðèÿ íå ìåíÿëàñü òîãäà òîëüêî ïðèñâàèâàþ íîâûå àòðèáóòû
if (!isCoordinate) makeNewAttrib();
else
{
x1a = X1Line->text().toDouble();
y1a = Y1Line->text().toDouble();
z1a = Z1Line->text().toDouble();
x2a = X2Line->text().toDouble();
y2a = Y2Line->text().toDouble();
z2a = Z2Line->text().toDouble();

MacroAnalizer* command = MainWindow::getApplication()->myMacAnalizer();
command->startUndo(); //Çàïèñûâàþ äëÿ îòìåíû !
myLabel.ForgetAllAttributes(Standard_True);
command->line(x1a,y1a,z1a,x2a,y2a,z2a,a_Name,R1,G1,B1);
command->endUndo(); //Çàêîí÷èë çàïèñü äëÿ îòìåíû !
}
isColor = false;
close();
}

void LineEditDialog::makeNewAttrib()
{

//Èìÿ, öâåòà, ìàòåðèàëû...
TDF_Label level0 = myLabel.FindChild(0,Standard_True);
if (isName)
TDataStd_AsciiString::Set(level0.FindChild(0), a_Name.toAscii().data()); //èìÿ

if (isColor)
{
Handle_TDataStd_IntegerArray anArray = new TDataStd_IntegerArray();
anArray->Init( 1,3 );
anArray->SetValue( 1, R1 );
anArray->SetValue( 2, G1 );
anArray->SetValue( 3, B1 );
Handle_TDataStd_IntegerArray anAttr =
TDataStd_IntegerArray::Set(level0.FindChild(1), anArray->Lower(), anArray->Upper()); //öâåò
anAttr->ChangeArray(anArray->Array());
}
}

LineEditDialog::~LineEditDialog()
{

}

void LineEditDialog::NameChanged()
{
isName = true;
}

void LineEditDialog::CoordChanged()
{
isCoordinate = true;
}

void LineEditDialog::closeEvent(QCloseEvent*) //Ïîýêñïåðèìåíòèðîâàëè è õîòÿò çàêðûòü !
{
if (isColor==true)
{
Quantity_Color color( R1 / 255., G1 / 255.,
B1 / 255., Quantity_TOC_RGB );
myObject->SetColor(color.Name());
myObject->Update();
}
}
//Çäåñü ïðîñìîòîðùèêè

void LineEditDialog::onColorClicked()
{
QColor aColor ;
if (isColor)
aColor.setRgb( R1a, G1a, B1a );
else
aColor.setRgb( R1, G1, B1 );

QColor aRetColor = QColorDialog::getColor( aColor );
if ( aRetColor.isValid() )
{
R1a = aRetColor.red();
G1a = aRetColor.green();
B1a = aRetColor.blue();
Quantity_Color color( aRetColor.red() / 255., aRetColor.green() / 255.,
aRetColor.blue() / 255., Quantity_TOC_RGB );
myObject->SetColor(color.Name());
myObject->Update();
isColor=true;
}
}