[OpendTect_Developers] help...how recieves a pair of coordinate
Glenn LB
blueck_1923 at hotmail.com
Thu Mar 14 19:39:45 CET 2013
Hi Ranojay,>Thanks for your response and your help, now i clearly can understand the use of the SeparString class, although i don't know if i used of way adequate the socket, my idea is make a connector between a app and OpendTect, the app should sent a ASCII file (contain coordinates and other data of well depth ) and OpendTect should receive and display these data in the scene . i made a code with socket but i can´t connect both apps. here code is only socket part:
>class MyServer : public TcpServer{public: MyServer();
protected: void newConnCB(CallBacker*); void socketReadyCB(CallBacker*);
};
MyServer::MYServer(){ const char* host = " 127.0.0.1"; /*For example*/ const bool res = listen(host , 23); newConnection.notify( mCB(this,MyServer,newConnCB) ); readyRead.notify( mCB(this,MyServer,socketReadyCB) );}
void MyServer::newConnCB( CallBacker* ){ uiMSG().message( "New connection established" );}
void MyServer::socketReadyCB( CallBacker* cb ){ mCBCapsuleUnpack(int,socketid,cb); TcpSocket* socket = this->getSocket( socketid ); if ( !socket ) return;
BufferString data; socket->read( data ); uiMSG().message( data );
SeparString str( data );BufferString type = str[0]; const int sceneid = ODMainWin()->sceneMgr().askSelectScene(); if ( type == "WellID" ) { MultiID mid( str[1] ); ODMainWin()->sceneMgr().addWellItem( mid, sceneid ); } else if ( type == "WellCoords" ) { PtrMan<CtxtIOObj> ctio = mMkCtxtIOObj( Well ); ctio->setName( str[1] ); ctio->ctxt.forread = false; uiIOObjSelDlg dlg( ODMainWin(), *ctio ); if ( !dlg.go() ) return;
const IOObj* wellioobj = dlg.ioObj(); if ( !wellioobj ) return;
WellImporter importer( str, *wellioobj ); if ( !importer.go() ) uiMSG().error( importer.errorMessage() ); else ODMainWin()->sceneMgr().addWellItem( wellioobj->key() , sceneid ); } else if ( type == "EMID" ) { uiTaskRunner tr( ODMainWin() ); MultiID mid( str[1] ); EM::EMObject* emobj = EM::EMM().loadIfNotFullyLoaded( mid, &tr ); ODMainWin()->sceneMgr().addEMItem( emobj->id(), sceneid ); }
}
> Any idea where I am going wrong this?>Regards>Glenn> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 13 Mar 2013 15:57:50 +0530
> From: Ranojay Sen <ranojay.sen at dgbes.com>
> To: developers mailing list <developers at opendtect.org>
> Subject: [OpendTect_Developers] Fwd: Fwd: help...how recieves a pair
> of coordinate
> Message-ID: <514054A6.7050302 at dgbes.com>
> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
>
>
> Hi Glenn,
>
> If I understand correctly from your previous posts, you need some kind
> of mechanism to send and receive coordinate values to and from other
> application using sockets. For that you have chosen SeparString class
> for converting the coordinates to string and then send them over the
> network, this I would say not a bad way to do this, other wise you could
> also have used IOPars, as they provide more features. In any case let me
> elaborate how you can use SeparString to include multiple coordinate
> values and send them via socket in the code snippet below.
>
> Coord coord( 100, 120 );
> SeparString coordstring;
> coordstring += coord.x;
> coordstring += coord.y;
>
> // now the socket part
> TcpSocket socket;
> socket.connectToHost( "host", port ); // e.g. host = "192.168.5.112"
> (any host on the network), port = 1212 (any port which you want to connect)
> socket.write( coordstring .buf() );
>
>
> // on the receiving end.
>
> There should be a callback when the data is received.
>
> void YourClass::dataReceivedCB( CallBacker* cb )
> {
> mCBCapsuleUnpack(int,socketid,cb); // we need the socket id as
> multiple client can connect to the server.
>
> TcpServer server;
> BufferString datarecvd;
> server.read( socketid, datarecvd );
> SeparString coordstring( datarecvd );
> Coord newcoord;
> newcoord.x = coordstring.getDValue( 0 ); // fist value X
> newcoord.y = coordstring.getDValue( 1 ); // second value Y
> }
>
> This code snippet roughly shows the mechanism of sending and recieving
> coordinate values with SeparString and sockets, please note copying this
> code directly will not work. In case you need more help please come back
> to me.
>
>
> Regards
> Ranojay
>
>
>
>
>
>
> Hi Everyone:
>
> I previously didn?t an adequate and accurate information about the
> problem I had and offer an apology. I've been researching what I really
> need, the problem is as follows:
> -Show the pocision (coordinates) of a well in the scene OpendTect.
>
> I raised the issue of the following way:
>
> -Receive a pair of coordinates (x, y)
>
> class uiOP_PlugwBringer : public uiDialog
>
> {
>
> public:
>
> uiOP_PlugwBringer( uiParent* p)
>
> : uiDialog(p,Setup("Well Positions",
> "Specify coordinates",
>
> mNoHelpID))
>
> {
>
>
> BufferString crdunit( "Coordinate " );
>
> crdunit += SI().getXYUnitString();
>
> coordx = new uiGenInput( this, crdunit,
>
> PositionInpSpec(PositionInpSpec::Setup(true)));
>
> }
>
>
> The problem in above the class is that the variable coordx only save a
> one coordinate (x), then when the class /SeparString str( data ); /then
> when the class receives the buffer string data, cannot separating
> because only contains one coordinate (x).
>
> bool acceptOK(CallBacker*)
>
> {
>
> BufferString data = coordx->text();
>
>
> if( ! *data)
>
> {
>
> uiMSG().error("Please type coordinates");
>
> return false;
>
> }
>
> SeparString str( data );
>
> BufferString type = str[0];
>
> const int sceneid =
> ODMainWin()->sceneMgr().askSelectScene();
>
> PtrMan<CtxtIOObj> ctio = mMkCtxtIOObj( Well );
>
> ctio->setName( str[1] );
>
> ctio->ctxt.forread = false;
>
> uiIOObjSelDlg dlg( ODMainWin(), *ctio );
>
> if ( !dlg.go() )
>
> return true;
>
>
> const IOObj* wellioobj = dlg.ioObj();
>
> if ( !wellioobj ) return true;
>
>
> WellImporter importer( str, *wellioobj );
>
> if ( !importer.go() )
>
> uiMSG().error( importer.errorMessage() );
>
> else
>
> ODMainWin()->sceneMgr().addWellItem(
> wellioobj->key() , sceneid );
>
> return true;
>
> }
>
>
> uiGenInput* coordxy;
>
> uiGenInput* coordx;
>
> uiGenInput* coordy;
>
>
> };
>
>
>
> if they have any idea how to fix this thank you for your help. best Glenn
>
>
> Dear all,
>
> Via OpendTect support, I got a request from Glenn for help in
> developing a plugin using sockets. This is typically a question
> one would post on OpendTect's developers list. Moreover, since
> I do not have a clue myself.
>
> He is referring to a contribution of Ranojay Sen to this developers
> mailing list, but the author is currently unavailable for celebrating
> his honeymoon.
>
> http://lists.opendtect.org/pipermail/developers/2011-April/000253.html
>
>
> =========================================================================
>
> Glenn LB <blueck_1923 at hotmail.com> wrote:
>
> > Thanks for answer me, i working in a Company that develop applications
> > for SIG and extensions for same, but this occasion, i will develop a
> > plugin in OpendTect that must receive a pair of coordinates x and y
> > or a file .shp or .txt of positions of wells, and display this ubication
> > of wells in the scene of OpendTect, i proof some ideas for example
> > how used a sockets, and how make a Callback, but hardly i know little
> > or nothing about the development in OpendTect, thanks for you help.
>
> > the examples I wanted to load are the following:
>
> > http://web.archiveorange.com/archive/v/L9Q23izaijPJS8r4EY6E ,
>
> > but i not know how to do it. thanks. best.
>
> > Glenn
>
> =============================================================================
>
>
> Best regards,
>
>
> Jaap Glas
>
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.opendtect.org/pipermail/developers/attachments/20130313/966c1bb2/attachment.html>
>
> ------------------------------
>
> _______________________________________________
> Developers mailing list
> Developers at opendtect.org
> http://lists.opendtect.org/mailman/listinfo/developers
>
> You receive this mail because you are listed on developers at opendtect.org To unsubscribe please go to http://lists.opendtect.org/mailman/options/developers . If you encounter any problems, please contact support at opendtect.org .
>
> End of Developers Digest, Vol 12, Issue 4
> *****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20130314/7db756a5/attachment.html>
More information about the Developers
mailing list